Setting background color for a JFrame

Retrieve the content pane for the frame and use the setBackground() method inherited from Component to change the color.

Example:

myJFrame.getContentPane().setBackground( desiredColor );

To set the background color for JFrame:

getContentPane().setBackground(Color.YELLOW);  //Whatever color

using:

setBackground(Color.red);

doesn't work properly.

use

Container c = JFrame.getContentPane();

c.setBackground(Color.red);

or

myJFrame.getContentPane().setBackground( Color.red );