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

Popular posts from this blog

android - Automated my builds -

how to proxy from https to http with lighttpd -

python - Flask migration error -