为什么我的代码不能正确更新 jtextpane 字体颜色?
Why doesn't my code correctly update the jtextpane font colour?
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);
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);