Marck Fp Marck Fp - 3 years ago 133
Java Question

(Java) how do I use checkbox generated with a for

I have a Problem, I generate some checkbox with a for and i need to use them but donĀ“t know how they are named to call them.

for(disponibility prov: dis){

JCheckBox check=new JCheckBox();

check.setBounds(30,156,97,33);

}

VHS VHS
Answer Source

Just use an array list type of structure to store all your checkboxes. Access them using an index later. If you want to name them based on some property of disponibility, you can use a map to store the checkboxes.

List<JCheckBox> list = new ArrayList<>();
for(disponibility prov: dis){    
   JCheckBox check=new JCheckBox();    
   check.setBounds(30,156,97,33);
   list.add(check);
}
//Later access nth checkbox
list.get(n).setEnabled(true);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download