tags:

views:

213

answers:

2

This is an exploratory query.

I am wondering if the following is possible with JTextArea?

Can I alter the text to bold (append text) and then back to normal and will it only display the bold text in bold and the rest as normal?

Also can the contents of JTextArea be saved as a RTF document?

Thank you.

+1  A: 

No. What you're looking for is JEditorPane

This supports HTML (3.2?) which will allow you to use <font> (and other older 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 I referenced above, JEditorPane also supports limited RTF. Don't forget to change the MIME to text/rtf

Matt
how would you go about appending text to JEditorPane? setText? getText?
iEisenhower
@ikurtz Yep, `setText(getText() + "...");`
Matt
@Matt: sorry but this does not work. as multiple <html></html> tags are introduced so only the first occurance is displayed and rest of the data ignored.
iEisenhower
A: 

I believe you need a JTextPane or JEditorPane for that.

JRL