How to Change JFrame Background Color

Generally, to change the background of JFrame you just have to call the JFrame method setBackground(Color c):

frame.setBackground(Color.BLUE);

JFrame contains more tricks that you can apply with the java Color class:

  • RGB values
  • Using methods like brighter, darker or lighter

There are also other methods to retrieve the color of components and more.

JFrame example setBackground(color) 

You can test this code in your IDE:

import java.awt.Color; 
import java.awt.Dimension;
import javax.swing.JFrame;

public class Test extends JFrame{

public static void main(String[] args) {

JFrame frame = new JFrame("JFrame test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);

frame.setPreferredSize(new Dimension(400, 300));
frame.getContentPane().setBackground(Color.ORANGE);
frame.pack();
frame.setVisible(true);
}
}
change JFrame background