Swing - Question about JEditorPane

Yesterday I asked about how to use JTextArea to allow different Color and Font for each line, and was directed to JEditorPane.

What I am doing is writing a chat client. So in the window where all the chat is printed, I want to be able to alternate Color and text for each line of text. So I try to use setText in JEditorPane and it is actually more unfriendly then append in JTextArea. It just overwrites the last entry with the new one, but the Font and color changes, for what little that is worth now.

So I used getText and appended that to the new string, and then called setText. Now it works exactly how JTextArea does. The entire text changes to the new Color and Font.

Not only that but now chat.setCaretPosition(chat.getDocument().getLength()); doesn't work very well. It does not force the the caret to move with the document allowing for autoscrolling.

Any more hints on how to reach my goals. The tutorial is supremely unhelpful as it doesn't have any dynamic examples for these classes.

[1032 byte] By [Rusty_Shackleforda] at [2007-11-26 23:25:38]
# 1

Actually, the advice was to use JTextPane or JEditorPane.

If you read the tutorial then you would know that JEditorPane is only used for displaying HTML Did you use HTML tags to color your text? Persionally I find it too difficult.

The JTextPane allows you to change the attributes of certain text. So I'll let you try the example from the tutorial on using text panes

.

camickra at 2007-7-10 14:33:09 > top of Java-index,Desktop,Core GUI APIs...