File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Changing Font in JTextArea for new text only Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Changing Font in JTextArea for new text only" Watch "Changing Font in JTextArea for new text only" New topic
Author

Changing Font in JTextArea for new text only

Ciaran Mooney
Ranch Hand

Joined: Jan 21, 2013
Posts: 72

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


I love deadlines, I love the whooshing sound they make as they fly by...
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4664
    
    5

Not with a JTextArea, no. Look in to using a JTextPane or JEditorPane.


luck, db
There are no new questions, but there may be new answers.
Maxim Karvonen
Ranch Hand

Joined: Jun 14, 2013
Posts: 106
    
  11
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

Joined: Jan 21, 2013
Posts: 72

Great thanks will have a look at the APIs
Ciaran
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Changing Font in JTextArea for new text only