OK, I have now uncovered a slightly different bug (at least it is different than the one I described earlier, but maybe I misremember).
Add the following to the DemoRootPane:
In createMenuBar() a few menu items to play with:
- Code: Select all
menu = new JMenu("Fontsize");
menu.add(new JMenuItem(new FontSizeAction(10)));
menu.add(new JMenuItem(new FontSizeAction(12)));
menu.add(new JMenuItem(new FontSizeAction(14)));
menu.add(new JMenuItem(new FontSizeAction(16)));
menu.add(new JMenuItem(new FontSizeAction(18)));
menu.add(new JMenuItem(new FontSizeAction(20)));
mb.add(menu);
A new method called setEditorFont:
- Code: Select all
public void setEditorFont(Font font) {
this.textArea.setFont(font);
SyntaxScheme myScheme = this.textArea.getSyntaxScheme();
Style[] styles = myScheme.styles;
for (int i = 0; i < styles.length; i++) {
if (styles[i] != null) {
styles[i].font = font;
}
}
this.textArea.setSyntaxScheme(myScheme);
this.scrollPane.getGutter().setLineNumberFont(font);
//this.scrollPane.setLineNumbersEnabled(false);
//this.scrollPane.setLineNumbersEnabled(true);
}
And not to forget the new FontSizeAction:
- Code: Select all
private class FontSizeAction extends AbstractAction {
private int fontSize;
public FontSizeAction(int fontSize) {
this.fontSize = fontSize;
putValue(NAME, "Change Fontsize to "+fontSize+"pt");
}
public void actionPerformed(ActionEvent e) {
setEditorFont(new Font("monospaced", Font.PLAIN, this.fontSize));
}
}
Now first select e.g. 20pt and then 10pt. The Line Number font changes, but the alignment of the border with the editor content is broken. Comment in the two LineNumbersEnabled calls and see it working fine.
If you comment out the
- Code: Select all
this.textArea.setFont(font);
call, it behaves in an interestingly different way.
If the syntax scheme is not manipulated, everything (apart from the explicitly set font styles in the current scheme) seems to work.
Maybe I am just confused on how to correctly change the fontsize in RSyntaxTextArea?
Have fun,
hubersn