jeudi 16 mai 2019

Java- How to retrieve selected values in a checkbox

The information is retrieved from a server, then populated in a checkbox. I'm trying to retrieve the selected patient name from the checkbox set but I'm falling to show the value that as been selected when you click the monitor button

I've created an arraylist of the patients, add the values to a checkbox array, added the listener to the button

private  ArrayList<JCheckBox> checkboxes = new ArrayList<JCheckBox>();


This creates the checkbox and display the checkbox of patients names.

for(Model.Patient p : set) {

           box = new JCheckBox(p.getFirstName());

           System.out.println(p.getFirstName() +" " + p.getId());
           add(box);
           checkboxes.add(box);
           }
}

This is the code that is giving problem I want to retrieve the patients name

if (box.isSelected()) {
                    for (JCheckBox checkbox : checkboxes)
                    {
                        test = box.getText();
                        System.out.println(test);

                    }

                }




Aucun commentaire:

Enregistrer un commentaire