2016-03-15 43 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

相關問題