java - Creating textField with unique name for each in a loop -


im beginner level programmer on java. create textfield in loop want have unique name (for calling after loop). ex. have loop;

for (int =0;i<x;i++)          {               composite composite_10 = new composite(composite_20, swt.border);             composite_10.setbackground(swtresourcemanager.getcolor(230, 230, 250));             composite_10.setbounds(x1, y1, 542, 76);              txtbaseseri = new text(composite_10, swt.border);             txtbaseseri.setmessage("base seri");             txtbaseseri.settooltiptext("");             txtbaseseri.setbounds(x2, y2, 95, 21);             txtbaseseri.settext("41");             txtbaseseri.settextlimit(7); } 

here, want second textfield have name txtbaseseri1, txtbaseseri2... can call them after exiting loop. there way ? in advance..

i want second textfield have name txtbaseseri1, txtbaseseri2 - there way that?

no. use arraylist instead , add text fields list, example this:

list<text> txtbaseseri = new arraylist<>(); (int = 0; < x; i++) {     // ...      text txt = new text(composite_10, swt.border);     // ...      txtbaseseri.add(txt); } 

afterwards, can access each text object through index, like

text first = txtbaseseri.get(0); text second = txtbaseseri.get(1); // ... 

or can loop through them, like

for (text txt : txtbaseseri) {     // in each loop iteration, txt set next element     // ... } 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -