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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies 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
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to set color of text in Text Area
 
Similar Threads
Changing the color of text printed in a TextArea.
how can i set the XOR mode of a JTextComponent
FTP upload
textarea array value stored in another array
Hiding button label when button is disable