Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the color of particular characters in JLabel?

How to change the color of particular characters in JLabel? For instance,

JLabel lbl = new JLabel("My Text");

I would like that My has blue color, while Text has red color. Is it possible?

like image 646
Klausos Klausos Avatar asked Feb 10 '12 09:02

Klausos Klausos


1 Answers

Yes, check How to Use HTML in Swing Components.

JLabel lbl = new JLabel("<html><font color=blue>My</font><font color=red>Text</font></html>");
like image 107
Marcelo Avatar answered Sep 19 '22 02:09

Marcelo