HELP! JEditorPane.setForeground()

I Can't seem to get JEditor and JtText panes to respect calls against setBackground() and setForeground() when displaying a StyledDocument. I checked the documentation and google and came up with this from the Sun Docs:

"The default varies based on the look and feel; to enable it set the client property with this name to Boolean.TRUE."

I'm not sure how to do this, as every time I have attempted it, it has not worked. I've literally blown 4 hours on this, and to be consistent with a GUI design I need to do this. Can someone help me?

[559 byte] By [Java_Vina] at [2007-11-27 10:09:57]
# 1

Sorry, I suppose I should have pasted more of the documentation, its unclear:

From the documentation for JEditorPane:

--

HONOR_DISPLAY_PROPERTIES

public static final String HONOR_DISPLAY_PROPERTIES

Key for a client property used to indicate whether the default font and foreground color from the component are used if a font or foreground color is not specified in the styled text.

The default varies based on the look and feel; to enable it set the client property with this name to Boolean.TRUE.

Since:

1.5

See Also:

Constant Field Values

--

Java_Vina at 2007-7-13 0:46:17 > top of Java-index,Java Essentials,Java Programming...
# 2

You use the JComponent method putClientProperty() to specify how the component should behave:import java.awt.Color;

import javax.swing.JEditorPane;

import javax.swing.JFrame;

import javax.swing.JSplitPane;

import javax.swing.SwingUtilities;

public class EdPaneEg extends JFrame {

public EdPaneEg() {

JSplitPane split = new JSplitPane();

add(split);

JEditorPane left = new JEditorPane("text/html", "Some text");

left.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true);

left.setForeground(Color.RED);

split.setLeftComponent(left);

JEditorPane right = new JEditorPane("text/html", "Some text");

right.setForeground(Color.RED);

split.setRightComponent(right);

}

public static void main(String[] args) {

SwingUtilities.invokeLater(new Runnable() {

public void run() {

EdPaneEg frame = new EdPaneEg();

frame.setTitle("Example");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.pack();

frame.setVisible(true);

}

});

}

}

pbrockway2a at 2007-7-13 0:46:17 > top of Java-index,Java Essentials,Java Programming...