2016-03-15 45 views
1
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字体颜色?

+0

也许setForeground不叫 – Stultuske

+0

我不知道要尝试什么其他的方法正确的方法是什么?当我调用构造函数时setForeground似乎可以工作,但当我尝试用它来改变初始颜色时,它不起作用 – Cypher236

+0

@ Cypher236看看我的解决方案并让我知道它是否解决了您的问题。 – user3437460

回答

2

而是直接在前台属性设置,您可能想这样做:

JTextPane textPane = new JTextPane(); 
StyledDocument doc = textPane.getStyledDocument(); 

Style style = textPane.addStyle("Blue", null); 
StyleConstants.setForeground(style, Color.blue); 
+0

不幸的是它没有工作:/ – Cypher236

+0

@ Cypher236嗯,我看我是否可以写一个迷你演示。 – user3437460

+0

好的,谢谢!感谢帮助 – Cypher236

相关问题