File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Changing Font in JTextArea for new text only

 
Ciaran Mooney
Ranch Hand
Posts: 74
Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am using a JTextArea for a text editor programme.
Text in the JTextArea is provisionally set in the constructor using teaxtArea.setFont("Serif", Font.PLAIN, 14);
I have added event handlers that allow user to select various font styles and sizes.
However when the new changes are applied via the setFont method the text already in the JTextarea is changed.

Is it possible to apply the new font to new text only?

Thanks
Ciaran
 
Darryl Burke
Bartender
Posts: 5115
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not with a JTextArea, no. Look in to using a JTextPane or JEditorPane.
 
Maxim Karvonen
Ranch Hand
Posts: 120
12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Ciaran.

JTextArea always use same text style for the whole text. You should use JEditorPane or JTextPane. See Using Text Components in Oracle Swing Tutorial for more details.
 
Ciaran Mooney
Ranch Hand
Posts: 74
Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great thanks will have a look at the APIs
Ciaran
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic