This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to set color of text in Text Area

 
arun mahajan
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Arun,
Have a look at javax.swing.text.StyledDocument.
It should work for you ...
Regards,
Manfred.
 
Vinod Venugopal
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic