i have main jpanel that's called board has jpanel in 2 `jbuttons' 1 of supposed remove panel when clicked.
public class aditwindow extends jpanel { private int width; private int height; public aditwindow(int x, int y){ super(); setlayout(new boxlayout(this, boxlayout.y_axis)); width=180; height=60; setbounds(x, y, width, height); jbutton addloc = new jbutton("add location"); jbutton addsign = new jbutton("add sign"); addloc.addactionlistener(new actionlistener() { public void actionperformed(actionevent e) { close(); system.out.println("click"); } }); addsign.addactionlistener(new actionlistener() { public void actionperformed(actionevent e) { system.out.println("addsign"); } }); main.font=main.font.derivefont(13f); addloc.setfont(main.font); addsign.setfont(main.font); addloc.setmaximumsize(new dimension(width, 30)); addsign.setmaximumsize(new dimension(width, 30)); addloc.setbackground(new color(0xf6f6f6)); addsign.setbackground(new color(0xf6f6f6)); add(addloc); add(addsign); main.board.validate(); private void close(){ system.out.println("close"); main.board.del(this); } } the del method is:
public void del(component c){ remove(c); validate(); system.out.println("removed"); } problem is: reason takes 2 clicks panel removed, lines printed on both clicks. unsure how manage situation.
eidt: if remove validate() line del() method work first click buttons dissapear leaving rectangle background of jpanel on screen.
you might try invoking remove/validate within swingutilities.invokelater() call.
Comments
Post a Comment