如何仅在JTextArea的部分中显示粗体文本?

iTE*_*Egg 7 java swing jtextarea

我可以将a的文本更改JTextArea为粗体(附加文本),然后恢复正常,它是否只显示粗体文本,其余部分正常显示?

也可以将内容JTextArea保存为RTF文档?

Mat*_*att 15

不,你要找的是JEdi​​torPane

这支持HTML(3.2?),允许您使用<font>(和其他较旧的标签)来提供富文本.

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

编辑:根据我上面提到的javadoc,JEditorPane也支持有限的RTF.不要忘记将MIME更改为text/rtf