Java Swing How to - Change background color of JFrame








Question

We would like to know how to change background color of JFrame.

Answer

import javax.swing.JFrame;
import java.awt.Color;
import java.awt.EventQueue;
/* w  w w .ja v  a 2  s .co  m*/
public class Main {

  public static void main( String[] args ) {
        JFrame frame = new JFrame();
        frame.getContentPane().setBackground( Color.PINK );
        frame.setSize( 200, 200 );
        frame.setVisible( true );
        frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
      
  }
}