我正在尝试为JTextArea中的String
设置多种文本颜色。我尝试过多种方法,例如:
<html>Text color: <font color='red'>red</font><font color ="black">Hi</font></html>
<html>Text color: <font color="red">red</font><font color ="black">Hi</font></html>
但它本身就是这样。我读过诸如使用JEditorPane或JTextPane之类的东西,我想到了它,但我不熟悉所有需要使用的东西。我最终必须学习它,但不是现在。
编辑:我了解到您无法使用颜色 JTextArea
答案 0 :(得分:2)
没有。 JTextArea
不能用于此。它仅支持纯文本。无论你在其中写下HTML
,它都会显示为原样。
作为替代方案,您可以使用JTextPane
或JEditorPane
。
检查文档:
JTextPane:http://docs.oracle.com/javase/7/docs/api/javax/swing/JTextPane.html
JEditorPane:http://docs.oracle.com/javase/7/docs/api/javax/swing/JEditorPane.html