[英]How to display bold text in only parts of 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
的文本更改为粗体(附加文本),然后再恢复为普通文本,是否仅将粗体文本显示为粗体,其余部分正常显示?
Also can the contents of JTextArea
be saved as an RTF document? 还可以将
JTextArea
的内容另存为RTF文档吗?
No. What you're looking for is JEditorPane 不,您要找的是JEditorPane
This supports HTML (3.2?) which will allow you to use <font>
(and other older tags) to provide rich text. 它支持HTML(3.2?),可让您使用
<font>
(和其他较早的标记)提供富文本。
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. 编辑 :根据我上面引用的javadoc,JEditorPane还支持有限的RTF。 Don't forget to change the MIME to
text/rtf
不要忘记将MIME更改为
text/rtf
我相信您需要一个JTextPane或JEditorPane 。
textArea.setFont(textArea.getFont().deriveFont(Font.BOLD, textArea.getFont().getSize()));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.