swing - Java, JPanel not displaying in JFrame, possible concurrency issue? -
i have vector of 4 frames consist of 2d array of jbuttons contained within jpanel. trying add these jframe display animation when looped.
i have add method works when increment manually, when put in loop frame stays blank if has not been repainted. terminal prints correct index numbers.
public void addnewframe() throws interruptedexception { (int = 0; < 10; i++) { if (index == 3) { system.out.println(index); remove(model.getframe(3)); revalidate(); repaint(); index = 0; add(model.getframe(index), borderlayout.center); revalidate(); repaint(); thread.sleep(300); } else { system.out.println(index); remove(model.getframe(index)); revalidate(); repaint(); index++; add(model.getframe(index), borderlayout.center); revalidate(); repaint(); thread.sleep(300); } } could concurrency issue? should adding 2d array of buttons jpannel running in it's own thread?
they display animation when looped.
don't use thread.sleep() attempt control animation.
animation should done using swing timer.
also, whenever see code remove/add of component wrong. instead should using cardlayout. tutorial above has section on how use cardlayout.
Comments
Post a Comment