Avatar of DJ_AM_Juicebox
DJ_AM_Juicebox asked on

JTextArea and font color per word

Hi,

I have a JTextArea that is logging user supplied messages. When I display the message, I'm doing something like this:

m_myTextArea.append("Bob says: " + msg);
m_myTextArea.append("Sally says: " + msg);
m_myTextArea.append("Server says: " + msg);

Is there a way I can make "username says: " green for example, then the rest of the message red?

Thanks
Java

Avatar of undefined
Last Comment
CEHJ

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
CEHJ

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
DJ_AM_Juicebox

Ok can you you JTextPane with scrollbars?

Since this is a chat application, what happens if the user gives me an html string like:

"<B>Hello</B>"

as a chat message, will JTextPane interpret it as such and really make that string bold when appended? I wonder if there are any security problems with that?

Thanks
CEHJ

>>Since this is a chat application, what happens if the user gives me an html string like...

Well if you append it as is, you will get html if the pane's content type is set to "text/html'

>>I wonder if there are any security problems with that?

Not particularly. If it's too 'advanced' it'll probably just get ignored



CEHJ

:-)
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck