我正在制作一个相当简单的文本编辑器,我对我的样式按钮有疑问。当我突出显示文本并单击“粗体”按钮时,文本会按预期粗体显示,但我的选择不再可见。我仍然可以取消所选内容的粗体、斜体或下划线,但您只是看不到所选内容。所以,我想知道是否有一个设置可以让我单击按钮,但保留我的选择?我尝试使用 JMenuItem 而不是 JButton,这似乎有效,但随后它使我的工具栏看起来很糟糕。下面是示例代码。
//frame and pane creation up here
JToolBar tool = new JToolBar();
JToggleButton boldButton = new JToggleButton("Bold");
boldButton.addActionListener(new StyledEditorKit.BoldAction());
tool.add(boldButton);
感谢任何帮助。
最佳答案
So, I'm wondering if there is a setting that will allow me to click the button, but keep my selection?
boldButton.setFocusable( false );
关于java - 单击 JButton 设置文本样式后保持选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4235804/