我有一个JToolBar
和一个JTextPane
。在工具栏上,我有加粗、下划线等按钮。我尝试添加一个按钮,按下该按钮会增加文本的大小。
此代码出现在我的 ToolBar 类的开头,并设置为等于我的 Display 类中的一个 int,它的默认值为 24。它用于设置原始字体大小。
static int size = Display.size;
此代码在我的 ToolBar() 构造函数中。
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));
由于某种原因,该按钮不起作用,但是如果我将代码更改为:
reduceButton.addActionListener(new StyledEditorKit.FontSizeAction("myaction-", 40));
..然后它工作。知道这是为什么吗?