java - How to change JLabel variable name at run time? -


i have more 100 jlabel components in jframe , have named them m1,m2,m3.... , want change text of each of them without doing manually.

so want set name of each label @ run time , change text, retrieving database.

this trying do:

jlabel j = new jlabel();   for(int i=0; i<100 ; i++) {        j.setname("m"+i);     j.settext(""+i); } 

you can create jlabel array .then can access m[x] example

jlabel m[] = new jlabel[100];   //initialize jlabel array before add  m[i]=new jlabel();  (int = 0; < m.length; i++) {      m[i].settext(""+i);      } 

the problem facing have named labels m1,m2 can't call dynamically making it's name.

m+"i".settext(); // impossible  

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - How to Hide Date Menu from Datepicker in yii2 -