How to display bold text only in parts of JTextArea?

Can I change the text of JTextArea to bold (add text) and then return to its normal state and will this bold font display in bold and the rest as usual?

Can the contents of JTextArea also be saved as an RTF document?

+6
java swing jtextarea
source share
2 answers

Not. What you are looking for, JEditorPane

This supports HTML (3.2?), Which will allow you to use <font> (and other old tags) to provide rich text.

 JEditorPane textarea = new JEditorPane("text/html", ""); textarea.setText("Here is some <b>bold text</b>"); 

EDIT . According to the javadoc that I referenced above, JEditorPane also supports limited RTF. Remember to change MIME to text/rtf

+13
source share

I believe you need a JTextPane or JEditorPane for this.

+1
source share

All Articles