How can I setbackground color for label?
1 posts in topic
Flat View  Flat View

Posted By:   mohan_reddy
Posted On:   Tuesday, April 3, 2001 06:55 AM

I have a frame .I added three labels(like one,two,three etc) to a frame.
each label i want to see each label with different color of background ,foreground.means
label one just like:-

Background color is black
Foreground color is blue
Label Two:-

Background color is yellow
Foreground color is red


and also
i want to see frame with another backgroundcolor.

Re: How can I setbackground color for label?

Posted By:   Christopher_Schultz  
Posted On:   Tuesday, April 3, 2001 07:22 AM

There's actually a method called Component.setBackground(java.awt.Color), which is the method that you want.

Here's a short example:

import java.awt.*;

public class awtTest extends Frame
public static void main(String args[])
awtTest t = new awtTest();
t.setTitle("AWT Test");
t.setLayout(new FlowLayout());
Label l = new Label("A label");


Note that for a Swing Label (javax.swing.JLabel), you must also call JComponent.setOpaque(true) so that the component will paint it's background color when it gets re-drawn.



About | Sitemap | Contact