java - Unable to set JPanel's Background in my Swing program. -
i set jpanel contentpane of jframe. when use: jpanel.setbackground(color.white); the white color not applied. but when use: jframe.setbackground(color.white); it works... surprised behaviour. should opposite, shouldn't it? sscce: here sscce: main class: public class main { public static void main(string[] args) { window win = new window(); } } window class: import java.awt.color; import javax.swing.jframe; public class window extends jframe { private container maincontainer = new container(); public window(){ super(); this.settitle("my paint"); this.setsize(720, 576); this.setlocationrelativeto(null); this.setresizable(true); this.setdefaultcloseoperation(jframe.exit_on_close); maincontainer.setbackground(color.white); //doesn't work whereas this.setbackground(color.white) works this.setcontentpane(maincontainer); this.setvisible(true); } }