Hello,
I want to be able to set different colors in different parts in a
JEditorPane. In order to do that, I try to use the
setCharacterAttributes method in DefaultStyledDocument.
However, when I call the method, it never returns.
The following snippet illustrates my problem. The "BEFORE" message
is shown, but the "AFTER" message is never shown.
StyleContext styleContext = new StyleContext();
DefaultStyledDocument styleDocument =
new DefaultStyledDocument(styleContext);
JEditorPane panel = new JEditorPane();
panel.setDocument(styleDocument);
panel.setEditable(false);
panel.setFont(new Font("SansSerif", Font.PLAIN, 10));
MutableAttributeSet attributes = new SimpleAttributeSet();
StyleConstants.setForeground(attributes, java.awt.Color.red);
System.out.println("BEFORE");
panel.setText("This is an example");
styleDocument.setCharacterAttributes(0, 4, attributes, false);
System.out.println("AFTER");
I hope you can help me with this problem.
Additionally, I'd like to be able to preserve text colored in previous
calls to setText. However, since there is not an append method, each
time I call setText all the text is replaced (and I suppose this means
to lose previous color settings). Perhaps you can give me some hint
in this problem. I'm confused.
Thanks in advance
_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing