Search code examples
javaswingjframejtextarea

How can i change the colour of certain words in a JTextArea?


I'm making myself a little messenger just for fun. And I want to make it so that when you see a certain word in there, for example your username it will be blue.

for example it will look something like this:

User1: Hello how are you?
User2: I'm fine thanks, what about you :)

(bold = blue, not bold = black)

This is how my client looks at the moment: The window

Anyway.. I hope this information will be enough for you to understand my question/ problem. Thanks :)


Solution

  • I'm afraid that JTextArea cannot contain HTML tags to change text color. It was designed to store plain text only. You might have to use JTextPane. Official info: http://docs.oracle.com/javase/tutorial/uiswing/components/text.html