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

    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(Color.black);
    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:
    Label.setBackground(silver);
    Label.setBackground(Color.silver);
    Label.setBackground(192,192,192);
    This all doesn't work.

    Can somebody help me with this?

    Thanks a lot from Holland!

  2. #2
    eRaaaa is online now Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    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!) ...how does the code looks like?! Give us more informations!

  3. #3
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,233
    Rep Power
    7

    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 );
    label.setBackground(...);

Similar Threads

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