File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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

How to set color of text in Text Area

arun mahajan
Ranch Hand

Joined: Dec 07, 2001
Posts: 305
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.
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 ...
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
subject: How to set color of text in Text Area
Similar Threads
Changing the color of text printed in a TextArea.
textarea array value stored in another array
Hiding button label when button is disable
FTP upload
how can i set the XOR mode of a JTextComponent