java - Repaint JPanel from actionlistener -


i know there multiple threats on how repaint jpanel. i've been trying repaint jpanel inside actionlistener applying revalidate() , repaint() methods (as found @ stackoverflow). sadly enough isn't working. when change text of button, it's repainting!

public simulationpanel() {       //configure panel.....        /* actionlistener */       btnstepsintofuture.addactionlistener(new actionlistener() {          @override         public void actionperformed(actionevent arg0)          {                            //do             /* refresh grid panel */             worldpanel.creategrid();             simpanel.revalidate(); //= not working             simpanel.repaint(); //= not working             //btnendsim.settext("end world simulation "); = working             //btnendsim.settext("end world simulation"); = working                   }       });       /* add components simulationpanel */      simpanel.add(buttonsontoppanel, borderlayout.north);      simpanel.add(worldpanel.getworldpanel(), borderlayout.center);      simpanel.add(stepsintofuturepanel, borderlayout.south); } 

extra info: worldpanel grid inside simulationpanel guess doesn't matter because repaint works changing text of buttons..

edit:

    public void creategrid(){      /* set constraint on gridbaglayout */     gridbagconstraints gbc = new gridbagconstraints();     /* create world grid panels */     (int row = 0; row < settingspanel.getnrofrows(); row++) {         (int col = 0; col < settingspanel.getnrofcolumns(); col++) {             /* add constraint correct dimension (row ; column) */             gbc.gridx = col;             gbc.gridy = row;              /* initialize new cell in world grid */             cellpanel cellpanel = new cellpanel();              /* draw elements of grid */             drawbackgroundicons(cellpanel, row, col);             drawborders(cellpanel, row, col);              worldpanel.add(cellpanel, gbc);         }     }     /* print overview */     printoverviewofworld();  }   /*  draw background icon of object */ public void drawbackgroundicons(cellpanel cellpanel, int row, int col) {     /*  set person, zombie weapon icon background image */     if(personarray[row][col] != null)     {         image img = new imageicon(this.getclass().getresource("/resources/"+personarray[row][col].getname()+".png")).getimage();         cellpanel.setimg(img);     }  } 

i let objects move 1 step on grid (right, left, up, diagonal, ...) changing position in twodimensional array.

how can make work revalidate/repaint methods?

cheers


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -