[ Setting multiple text colors in a String in a JTextArea ]
I am attempting to set multiple text colors for a String
in a JTextArea. I have tried multiple things such as:
<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>
But it just appears as that itself. I read things such as use JEditorPane or JTextPane and I thought of it but I'm unfamiliar with all the things that'd require to use. I'd have to learn it eventually but not now.
EDIT: I have learned that you can't use colors on JTextArea
Answer 1
No. JTextArea
cannot be used for that. It supports only and only plain text. Whatever HTML
you write in it, will appear as it is.
As an alternative, you can either use JTextPane
or JEditorPane
.
Check docs:
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