简体   繁体   中英

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:

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: 窗户

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM