0

I am trying to make a planner and want to change the background of my JFrame. I have already tried frame.getContentPane().setBackground(Color.); but that doesn't seem to work.

Here is the code for the frame portion

`public Planner(){
    frame = new JFrame();
    main = new JPanel();
    menu = new Menu(this);
    frame.setPreferredSize(preferredSize);
    frame.add(main);
    frame.setJMenuBar(menu);
    frame.pack();
    frame.setVisible(true);
    frame.setLocationRelativeTo(null);
    frame.setIconImage(Toolkit.getDefaultToolkit().getImage("Icon.png"));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setTitle("Myva");

    JLabel loading = new JLabel();
    JOptionPane pane = new JOptionPane();
    pane.showMessageDialog( null, "Hi. ");
    name = pane.showInputDialog("What is your name:");

}

Thanks in advance

2 Answers2

1

If I understand your question, then you could call JFrame.setBackground(Color) like

frame.setBackground(Color.BLUE);

If you want to change the color in a more visible manner, you can make it on a JPanel. Like,

public static void main(String[] args) {
    JFrame frame = new JFrame();
    JPanel panel = new JPanel();
    panel.setBackground(Color.BLUE);
    frame.add(panel);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(640, 480);
    frame.setVisible(true);
}

which will give you a very BLUE window.

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
0

To change the color of your JFrame, use the following code:

frame.setBackground(Color.BLUE);

(Color doesn't have to be blue, I just used it as an example)

Wyatt Lowery
  • 513
  • 1
  • 7
  • 21