Q:

Java - Swing setting colour to text in JTextArea

I have a JTextArea which has its text set to a string of information. In this string of information I have a variable which I would like coloured red, to do this I edit the string as follows:
"Result: <html><font color=red>" + negativeValue + "</font></html>"

I would expect this to give Result: ## where the number is red. However it just puts the following into the text area:
Result: <html><font color=red>##</font></html>

I'm not really sure how to get this working, so could someone offer advice as to how to do so?

A:

JTextArea is not a component designed for styled text.  If the text can be all one color, call setForeground(Color).  
Otherwise use a styled text component such as a JEditorPane or JTextPane.  For more info. on using them, see How to Use Editor Panes and Text Panes.
Also as pointed out by others, the entire String must start with <html> .

