Changing text color in JLabel

Hi,
How do I change font color on JLabel?
LVL 1
Leonid99Asked:
Who is Participating?
 
cini_gmConnect With a Mentor Commented:
Its simple..
 Suppose ur label is label1
 label1.setForeground(Color);
eg:
 label1.setForeground(Color.blue);
0
 
Igor BazarnyCommented:
label.setForegorund()
0
 
Igor BazarnyCommented:
Oops,
it should be label.setForeground()
0
 
tomboshellCommented:
Use some html coding in the label's string.  Then set the font in the html.  
ex.
String lTxt=new String("<html><font color='blue'>Hey my font color is set!</font></html>");
JLabel lab=new JLabel(lTxt);

Then you can also use the font families, bold, italic and such that are available to html.  This also works great when you are setting the message in a JOptionPane and want to bring empahsis to certain lines or are working on formating with the <p> tag.  

Tom
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.