• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to display more than one text colors in JTextArea?

 
Caton Chang
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sir,
JTextArea has no AttributeSet function with it , but It is more efficient than JTextPane.
How can I give the text color and font attributes to JTextArea?
Thanks a lot!
 
Dave Wingate
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JTextArea has a setFont(Font f) method. Will that suit your purposes?
Also, JTextArea inherits a method called setSelectedTextColor(Color) from JTextComponent. Is that what you're looking for?
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"catonchang" -

Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy.
You can change it here.

Thanks! and welcome to the JavaRanch!
 
Caton Chang
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dave Winn:
JTextArea has a setFont(Font f) method. Will that suit your purposes?
Also, JTextArea inherits a method called setSelectedTextColor(Color) from JTextComponent. Is that what you're looking for?

--------------------------------------------------
Hi Dave Winn,
Tanks for your answer!
I need more than one text colors in JTextArea,just like JBuilder have different colors for different set of KeyWords.
How can I do?
Caton
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To use styled text, you'll have to use one of the text components that support it, JEditorPane or JTextPane. The reason that JTextArea is more "efficient" is because it doesn't support those options.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!