java - JLabel's randomly not showing images on JFrame -
okay i'm writing program test using jlabels put lot of images on jframe going until strange bug happens random images on jframe didn't show up, resizing or moving frame off screen , on again make them show up. have no idea what's causing this.
but here's happens 90% of time:
http://i.imgur.com/y4u8k5c.png
http://i.imgur.com/fsggkkd.png
now here's code:
public class jframetest extends jframe{ int maxx=20; int maxy=20; int coords[][]; imageicon wallimage = new imageicon(getclass().getresource("/resources/wall.png")); imageicon floorimage = new imageicon(getclass().getresource("/resources/floor.png")); imageicon voidimage = new imageicon(getclass().getresource("/resources/void.png")); jpanel jpan=new jpanel(); public jframetest(){ coords = new int[maxy][maxx]; settitle("testframe"); setresizable(false); setdefaultcloseoperation(jframe.exit_on_close); setsize(1200,800); jpan.setsize(1200, 800); add(jpan); jpan.setlayout(null); setvisible(true); for(int =0; i<coords.length;i++){ for(int j =0; j<coords[i].length; j++){ if (coords [i][j] == 0) drawwalls(i*64,j*64); } } } public void drawwalls(int x,int y){ jlabel pic2 = new jlabel(); pic2.seticon(wallimage); jpan.add(pic2); add(jpan); pic2.setbounds(new rectangle(new point(y,x),pic2.getpreferredsize())); pic2.setvisible(true); setvisible(true); } }
does have idea of what's happening here?
use setvisible(true) @ end , there no point of calling setvisible() on jlabel object. use update method @ end
jpan.update();
Comments
Post a Comment