private JTextPane textPane;
private String filename;
...
...
...
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter (saveFile)); //FileWrite mit BufferedWriter benutzen (optimiertes vorgehen)
Scanner sc = new Scanner(textPane.getText()); //Um in den Windows Editor die Umbrüche mitzuspeichern
String newline = System.getProperty("line.separator");
while(sc.hasNextLine())
{
bw.write(sc.nextLine());
bw.write(newline);
}
bw.flush( );
bw.close( );
filename = saveFile.getName(); //diese Methode gibt auch immer die Dateiendung mit zurück
setTitle(filename.substring(0, filename.lastIndexOf(46)) + " - MyEditor"); //ASCII 46 entpricht dem char Punkt
}
catch (IOException ioe)
{
ioe.printStackTrace( );
}
...
...
...
class MyForeAndBackroundActionListener implements ActionListener
{
private JTextPane textPane;
private SimpleAttributeSet attributes;
private JPanel colorPanelB;
private JPanel colorPanelF;
public MyForeAndBackroundActionListener(JTextPane textPane, SimpleAttributeSet attributes, JPanel colorPanelB, JPanel colorPanelF)
{
this.textPane = textPane;
this.attributes = attributes;
this.colorPanelB = colorPanelB;
this.colorPanelF = colorPanelF;
}
@Override
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("fontBackgroundButton"))
{
Color newColor = JColorChooser.showDialog(null, "MyEditor - Hintergrundfarbe", Color.WHITE);
if(!(newColor == null))
{
colorPanelB.setBackground(newColor);
StyleConstants.setBackground(attributes, newColor);
textPane.setCharacterAttributes(attributes, true);
}
}
}