Solved

Changing text color in JLabel

Posted on 2002-04-09
4
1,249 Views
Last Modified: 2007-12-19
Hi,
How do I change font color on JLabel?
0
Comment
Question by:Leonid99
  • 2
4 Comments
 
LVL 7

Expert Comment

by:Igor Bazarny
ID: 6928773
label.setForegorund()
0
 
LVL 7

Expert Comment

by:Igor Bazarny
ID: 6928775
Oops,
it should be label.setForeground()
0
 
LVL 7

Expert Comment

by:tomboshell
ID: 6930610
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
 

Accepted Solution

by:
cini_gm earned 50 total points
ID: 6930625
Its simple..
 Suppose ur label is label1
 label1.setForeground(Color);
eg:
 label1.setForeground(Color.blue);
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
count11 challenge 6 47
word0 challenge 4 54
wordcount challenge 11 76
eclipse compiler vs Installed JREs option 3 40
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now