• Post Reply Bookmark Topic Watch Topic
  • New Topic

mutilple color text in Jtextarea or JTextPane

 
ivin jacob
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am using jtextarea to display status of each file i am tring to extract.
Based up on success or failure , i want the color of the status text displayed in the textarea to be changed like (black for success and red for failure).

Can this be done using Jtextarea , or are there any other alternative.
 
Rob Spoor
Sheriff
Posts: 20817
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JTextPane supports StyledDocuments, with which you can set text attributes for specific parts of text.
Most notably, you'll like the setCharacterAttributes method.

As for the attribute set, use SimpleAttributeSet combined with StyleConstants to set or clear the style settings.
 
Brian Cole
Author
Ranch Hand
Posts: 920
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by ivin jacob:
i want the color of the status text displayed in the textarea to be changed like (black for success and red for failure).


Here's a simple JTextPane example.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!