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");
l.setBackground(Color.blue);
t.add(l);
t.pack();
t.setVisible(true);
}
}
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.
HTH
-chris