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

Wanna color some words in my JTextArea- -urgent  RSS feed

 
Saskia Schreiber
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I would be very glad if anyone could help me with my problem. I got a JTextArea and only some of the words should be red or bold or something. But I cannot use this JTextPane....
Would be great if somebody could help :-)
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

JTextArea ? JTextPane
assuming JTextArea:
The data model for the JTextArea is the PlainDocument implementation. This restricts the JTextarea to have
single-attributed text. In other words, it single font
and single color. Sorry!
regds.
- satya
 
Saskia Schreiber
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the very fast reply :-)
 
San Su
Ranch Hand
Posts: 313
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I never did this before. But i can point you some direction.

JTextComponent expose a method called "setDocument", It seems
you can set any document type ( PlainDocument, StyledDocument.. ) to any class derives from JTextComponent. By
default, JTextArea, JTextField, and JPasswordField use PlainDocument as their model. JTextPane uses an instance of DefaultStyledDocument by default. This doesnt mean that you cant change the Document model of those components. You can set any document to any JTextComponent. Look at the following site..
http://manning.spindoczine.com/sbe/files/uts2/Chapter19html/Chapter19.htm
It will help you alot.
[This message has been edited by Sankar Subbiah (edited July 09, 2001).]
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Just clarifying...
I din't mean to say this can't be acheived.
You probably could change the behavior by changing
the data model.
What I mentioned earlier applies to the default behavior.
Should have mentioned it earlier.
Sankar:
Thanks for following-up.
regds.
- satya
 
Harry Pfohl
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Labels and buttons may understand setText("<html><font size=+2 color=#0000ff>animated Button</html>");
I think a TextArea doesn't work so.
But why didn't you take a JEditorPane instead of a TextArea.
In a JEditorPane you can give out the text in html and format it with html-tags.
[This message has been edited by Harry Pfohl (edited July 09, 2001).]
[This message has been edited by Harry Pfohl (edited July 09, 2001).]
[This message has been edited by Harry Pfohl (edited July 09, 2001).]
[This message has been edited by Harry Pfohl (edited July 09, 2001).]
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried adding html to my setText for my JEditorPane and it didn't work.
 
Khurram Mahmood
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
U can use JTextPane instead of JTextArea u will get ur desired results.

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