Results 1 to 3 of 3
  1. #1
    Jan D is offline Member
    Join Date
    Jan 2012
    Rep Power

    Default Change backgroundcolor of Labels

    Hello everyone,

    I have a question about changing the color of a Label,
    Normally i should use this: Label.setBackground(;
    But i want to use more collors wich are not implemented in Java, so i created the myselve:
    Color gold = new Color(255, 215, 0);
    Color silver = new Color(192, 192, 192);

    When I want to use these self-created colors to change this Background of the label, it's not possible.
    I tried this for example:
    This all doesn't work.

    Can somebody help me with this?

    Thanks a lot from Holland!

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Rep Power

    Default Re: Change backgroundcolor of Labels

    Label.setBackground(silver); should work, if Label ist the variable name of the label (if so, read the naming conventions :D)
    Is there a compiler error?
    Do you use the setBackground method in an inner class and silver is a local variable? (then it must be final!) does the code looks like?! Give us more informations!

  3. #3
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Rep Power

    Default Re: Change backgroundcolor of Labels

    Assuming this is Swing (I don't know how AWT works) you need to make the labels opaque first:

    Java Code:
    label.setOpaque( true );

Similar Threads

  1. Width of labels containing html
    By pbrockway2 in forum AWT / Swing
    Replies: 2
    Last Post: 04-22-2011, 07:37 AM
  2. Java Backgroundcolor
    By java_beginner_ in forum New To Java
    Replies: 1
    Last Post: 10-31-2010, 03:39 PM
  3. Printing labels to A4
    By eggy524 in forum New To Java
    Replies: 3
    Last Post: 09-23-2010, 05:53 PM
  4. size och swt labels
    By larsk in forum SWT / JFace
    Replies: 0
    Last Post: 10-04-2009, 01:01 PM
  5. Aligning Labels
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-02-2008, 07:26 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts