如何仅在JTextArea的部分中显示粗体文本? [英] How to display bold text in only parts of JTextArea?

查看:142
本文介绍了如何仅在JTextArea的部分中显示粗体文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

还可以将 JTextArea 的内容保存为RTF文档吗?

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

推荐答案

没有。你要找的是 JEditorPane

这支持HTML(3.2?),它允许您使用< font> (以及其他旧版代码)提供富文本。

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>");

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

EDIT: According to the javadoc I referenced above, JEditorPane also supports limited RTF. Don't forget to change the MIME to text/rtf

这篇关于如何仅在JTextArea的部分中显示粗体文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆