Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

change textArea font color  RSS feed

 
chen young
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,


How can I do dynamically change of font color in textArea ?

For example:

For the first line I will use blue color:
textArea.setForeground(Color.BLUE);
textArea.append("first");

for the next line I want to use:
textArea.setForeground(Color.BLACK);
textArea.append("second");

I try repaint but it’s not working

Thanks

 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A JTextArea can only show one color. Either all text is black, or all text is blue - you can't mix it.

You can using JTextPane, and its StyledDocument. With these, you can set the character attributes. For instance:
 
chen young
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!