Andrew Thompson said:
JLabel l = new JLabel("Stop!");
l.setBackground( Color.RED );
And of course, you can use HTML as well..
__________________________
import java.awt.*;
import javax.swing.*;
public class JColoredBG extends JFrame
{
String html =
"<html><body bgcolor=#00ff00>" +
"<p>Go!</p>" +
"</body></html>";
public JColoredBG()
{
super("Colored Labels");
Container c = getContentPane();
c.setLayout(new GridLayout(0,1));
JLabel l1 = new JLabel("Stop!");
l1.setBackground( Color.RED );
// very important, default is transparent..
l1.setOpaque(true);
c.add(l1);
/* Swing text components can render simple
html but load several meg worth of classes
to do so apparently. */
JLabel l2 = new JLabel(html);
c.add(l2);
pack();
setLocation(25,25);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
setVisible(true);
}
public static void main(String args[])
{
new JColoredBG();
}
}
________________________________