如何在JTextArea中使用html标签 [英] How to use html tags in JTextArea
问题描述
当我尝试使用
textArea.setText(< html>< font color = \red \>嗨< / font>< / html>)
<显示的文本基本上是在setText方法内写入的全部文本。但类似的东西适用于JLabel,JButton等。
我怎么能为JTextArea做这件事?
-
不要为
Html $使用
JTextArea
c $ c>格式化对象
(甚至可能,但为什么要麻烦) - 使用
JTextPane
/JEditorPane
改为( setContentType(text / html)) -
使用
JavaFX
Html5
,
注意,今天在
由Oracle官方API实现的Java和方法
仅支持减少使用css< = Html 3.2的Html语法
When I try to change color of a JTextArea using
textArea.setText("<html> <font color=\"red\"> Hi </font></html>")
, the text is shown is basically the whole text written inside setText method. But similar things work for JLabel, JButton etc.
How can I do that for a JTextArea also?
don't to use
JTextArea
forHtml
formattedObject
(even is possible, but why bothering)use
JTextPane
/JEditorPane
instead (setContentType("text/html"))notice, todays Java and methods implemented in
Official API by Oracle
supporting only reducedHtml syntax with css <= Html 3.2
use
JavaFX
in the case that you want/need to use todaysHtml5
,
这篇关于如何在JTextArea中使用html标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!