• Post Reply Bookmark Topic Watch Topic
  • New Topic

Changing Fonts.

 
Atrus Greyor
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a JTextArea, if I have text that is in a perticular font, such as Times New Roman, how would I make it read the string, change the font and then replace what is there?

Thank you in advance!
 
Eddie Vanda
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try something like:

You then may need to call repaint () on the panel.
 
Atrus Greyor
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But would that work for a JTextArea?

Or would that just change the indivdual strings?
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JTextArea only supports one font at a time. If you want to change fonts, colors, highlights or other attributes for words, strings or paragraphs then you will need a JTextPane with a StyledDocument. The Swing tutorial has a discussion and example code that will help you get started.
 
Atrus Greyor
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you! That answers a lot of questions!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!