I have a JToolBar
and a JTextPane
. On the toolbar I have buttons for bolding, underlining, etc. I tried to add a button that, when pressed, would increase the size of the text.
This code appears at the start of my ToolBar class, and is set equal to an int from my Display class where it has a default value of 24. It's used to set the original font size.
static int size = Display.size;
This code is in my ToolBar() Constructor.
final JButton reduceButton = new JButton(new ImageIcon("res/reduce.png"));
reduceButton.setToolTipText("Reduce Text...");
reduceButton.setFocusable(false);
reduceButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
size -= 4;
System.out.println("FontSize = " + size);
}
});
reduceButton.addActionListener(new StyledEditorKit.FontSizeAction("myaction-", size));
For some reason the button doesn't work, however if I change the code to:
reduceButton.addActionListener(new StyledEditorKit.FontSizeAction("myaction-", 40));
..then it works. Any idea why this is?