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.

Recommended Answers

All 3 Replies

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

bump. please help

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.