This is some code to create a basic java window:
JPanel pane = new JPanel();
gui(String title){
super(title);
setBounds(100,100,500,500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container con = this.getContentPane();
* con.setBackground(new Color(0,0,0));
con.add(pane);
setVisible(true);
}
The line marked with a star (*) is meant to make the window’s background color black (0,0,0). However, that line seems to do nothing. (I have tried using pane.setBackground here, but that made no diffference.)
How do I change the background color?
You have added the
JPanelover theJFramewhich completely blocks out the underlying container on which you have set the color.You could do this instead: