This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript 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: 21044
85
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!