我正在尝试为 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>
但它本身就是这样出现的。我阅读了诸如 use JEditorPane 或 JTextPane 之类的内容,并且想到了它,但我不熟悉需要使用的所有内容。我最终必须学习它,但不是现在。
编辑:我了解到您不能在 JTextArea
最佳答案
没有。 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
关于java - 在 JTextArea 的字符串中设置多种文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31217600/