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!
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!
Re: Change backgroundcolor of Labels
Assuming this is Swing (I don't know how AWT works) you need to make the labels opaque first:
Code:
label.setOpaque( true );
label.setBackground(...);