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字體顏色?
也許setForeground不叫 – Stultuske
我不知道要嘗試什麼其他的方法正確的方法是什麼?當我調用構造函數時setForeground似乎可以工作,但當我嘗試用它來改變初始顏色時,它不起作用 – Cypher236
@ Cypher236看看我的解決方案並讓我知道它是否解決了您的問題。 – user3437460