How do I set a JLabel's background color?

Solution 1:

Use

label.setOpaque(true);

Otherwise the background is not painted, since the default of opaque is false for JLabel.

From the JavaDocs:

If true the component paints every pixel within its bounds. Otherwise, the component may not paint some or all of its pixels, allowing the underlying pixels to show through.

For more information, read the Java Tutorial How to Use Labels.

Solution 2:

The JLabel background is transparent by default. Set the opacity at true like that:

label.setOpaque(true);