Ideally my program should work like this...

Upon button click a random message (out of 3 messages) is appended to a text area(or pane, etc).
One message should display blue, one green and one red.

Currently I am using JTextPane. I have figured out how to append text easily but I cannot get it to show up in the designated color. When using html tags, it doesn't append at all. When I change the foreground color of the text, all of the text changes to one color.

Which would best method to use for what I am trying to do, and how? I've googled everything I can think of and can't find a good example.

4 Years
Discussion Span
Last Post by JamesCherrill

I think JTextPane is the class to use. I can't find any sample code on my PC. Try Google.


The HTML approach works, although you will have some code to wrtite to update the actual text without messing uip the HTML tags.
The "ideal" solution is to use a JTextPane and set the attributes. This link shows a nicely packaged solution - you could extend that, or just use it to see how color attributes can be applied to inserted text.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.