Font displayFont = new Font(Font.SANS_SERIF, Font.BOLD, 18);
WindowManager.getInstance().getConsoleWindow().getTextArea().setFont(displayFont);
WindowManager.getInstance().getConsoleWindow().getTextArea().setForeground(Color.BLUE);
上面是我的代码片段,负责在单击按钮时更改 jtextpane 中文本的属性。文本正确更新为更大和粗体,但它不会改变颜色,我不知道为什么。提前致谢。
最佳答案
您可能想要这样做,而不是直接在前台属性上设置:
JTextPane textPane = new JTextPane();
StyledDocument doc = textPane.getStyledDocument();
Style style = textPane.addStyle("Blue", null);
StyleConstants.setForeground(style, Color.blue);
关于java - 为什么我的代码没有正确更新 jtextpane 字体颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36010455/