我正在尝试使用 JTextPane 制作文本编辑器,但在设置所选文本颜色时遇到问题。这是最好的方法(但显然,不起作用):
JMenuItem button = new JMenuItem("Set Color");
toolbar.add(button);
button.addActionListener(new ActionListener( ) {
public void actionPerformed(ActionEvent e) {
Color c = JColorChooser.showDialog(frame,"Choose a color", getBackground());
textPane.getSelectedText().StyledEditorKit.ForegroundAction("color",c);
}
});
关于如何让它发挥作用的任何建议?还是有更好的方法?
谢谢