Cypher236
Cypher236

Reputation: 527

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);

The above is my code snippet responsible for changing the properties of the text in my jtextpane when I click a button. The text correctly updates to become larger and bold however it doesn't change the colour and I have no idea why. Thanks in advance.

Upvotes: 1

Views: 106

Answers (1)

user3437460
user3437460

Reputation: 17454

Instead of setting directly on the foreground property, you may want to do this:

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

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

Upvotes: 2

Related Questions