java - How to add few the same image in one program by using JLabel? -
i'm using swing , i'm trying add picture in program.
field = new jformattedtextfield(formatter); imageicon icon = new imageicon("background.png"), icon1 = new imageicon("1.png"); jlabel background = new jlabel(icon); jlabel firsticon = new jlabel(icon1); jpanel center = new jpanel(new gridlayout(0, 1)); public void initcomponents() { this.getcontentpane().add(center, borderlayout.center); center.add(background); field.setbounds(50,50); background.add(field); background.add(fristicon); }
with code working, when try add same picture "background.add(fristicon);" again don't see image added first. every new image deleting last icon.
you can't add several times same component.
i suggest proceed this:
for(int i=0;i<n;i++){ jlabel img=new jlabel(icon1); switch(i){ case 0: img.setbounds(x,y,w,h); break; case 1: img.setbounds(x,y,w,h); break; default: break; } background.add(); }
n equals number of icon want display
but jlabel not recommended container. suggest use jpanel container labels
Comments
Post a Comment