java - swing gui flickering white error -
i have gui i'm making program has outer container centered jframe contains inner container holds 22*12 cells. when run program, background flickers white , stays that. if point me out i'm going wrong awesome!
public class gui extends jframe { private jpanel outer, inner; private jlabel[][] labels = new jlabel[22][12]; public gui() { setbackground(color.black); setsize(1000,1000); setdefaultcloseoperation(jframe.exit_on_close); setlayout(new borderlayout()); outer = new jpanel(); outer.setlayout(new borderlayout()); outer.setsize(620,920); outer.setbackground(color.white); inner = new jpanel(); inner.setlayout(new gridlayout(22,12,10,10)); inner.setsize(600,900); inner.setbackground(color.white); (int = 0; < 22; i++) { (int j = 0; j < 12; j++) { labels[i][j] = new jlabel(); jlabel label = labels[i][j]; label.setsize(50,50); label.setbackground(color.gray); inner.add(label); } } outer.add(inner, borderlayout.center); add(outer, borderlayout.center); } }
the gui set visible in main class instantiates it.
the gui created , sized correctly. starts out black background randomly turns white after , stays that.
edit: if still important:
public static void main(string[] args) { swingutilities.invokelater(new runnable() { public void run() { gui gui = new gui(); gui.setvisible(true); } }); }
use new static variable names follow final static naming convention. variable should upper cased:
//setbackground(color.black); setbackground(color.black);
don't use setsize() components. instead add components frame , use pack() method components displayed @ preferred size:
//setsize(1000,1000); add(component1); add(anothercomponent); pack();
layout managers use preferred size not size layout tip:
//label.setsize(50,50); label.setpreferredsize(new dimension(50, 50));
this main problem. jlabel transparent default, background color set ignored:
label.setbackground(color.gray); label.setopaque(true);
by way, screen height 738, won't event able see entire frame since want height of 22*50. should aware of , add panel jscrollpane people me can use application. why should not hardcode preferred size.
Comments
Post a Comment