aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How to set color of text in Text Area Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to set color of text in Text Area" Watch "How to set color of text in Text Area" New topic
Author

How to set color of text in Text Area

arun mahajan
Ranch Hand

Joined: Dec 07, 2001
Posts: 305
Hi,
I have made a program which has a JTextArea. Now I want to append text in different color in it. What i mean that if the first line is in black color than next will be in red color and next will be in blue color and so on...
The problem is if I try to use setForeground it takes the last set color as this is the same component.
Can somebody help me to achieve this.
regards,
Arun
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Arun,
Have a look at javax.swing.text.StyledDocument.
It should work for you ...
Regards,
Manfred.
Vinod Venugopal
Ranch Hand

Joined: Dec 06, 2000
Posts: 148
But if Im not mistaken its possible to do so in a JTextPane , but not in a JTextArea.
Manfred, pls correct me if I'm wrong.


- Vinod<br />-------<br />SCJP2
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to set color of text in Text Area