Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How do I have a multicolored text in JTextArea? (VERY URGENT )  RSS feed

 
Anu
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone pls help me in adding multicolored text in JTextArea, for example, 2 line of blue and then 4 in black and then again 2 lines in blue.
Please help me asap....!!
Anukampa.
 
pratap malani
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,
i found that this cannot be done in jdk 1.2 i dont know abt. 1.3
thanks

Originally posted by anukampa malhi:
Can anyone pls help me in adding multicolored text in JTextArea, for example, 2 line of blue and then 4 in black and then again 2 lines in blue.
Please help me asap....!!
Anukampa.

 
Anu
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you are correct that i shd u use JTextPane but i m not able to get how can i actually use it. I have spend almost 3 days to work thru JTextPane but of no use. Can u please help me in same.
Thanx
Anukampa
 
ming fan
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's some sample code about how to use JTextPane:
JTextPane textPane = new JTextPane(new DefaultStyleDocument());
SimpleAttributeSet s = new SimpleAttributeSet();
StyleConstants.setFontFamily(s, "Times New Roman");
StyleConstants.setFontSize(s, 16);
StyleConstants.setBold(s, true);
StyleConstants.setForeground(s, Color.red);
textPane.getDocument().insertString(0, "hi, I am here\n", s);
Hope this helps.
Originally posted by anukampa malhi:
you are correct that i shd u use JTextPane but i m not able to get how can i actually use it. I have spend almost 3 days to work thru JTextPane but of no use. Can u please help me in same.
Thanx
Anukampa

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!