mardi 23 février 2016

how to use select all option in checklistbox in swing java?

In my snippet code! "checkBoxList" has no of files that are chosen by a file chooser and stored in it

check box "tmp" it has checkboxes for the files!

When i display the files[checkboxlist] in my panel.It comes as unchecked! After I have the option for tick/untick it.

I have the below code for select/unselect option

I need to know when I display the files!The files should display with checked(tick) Then I can modify which I can tick/untick.

I stuck on this logic!

public void selectAllMethod() {
Iterator<JCheckBox> i = checkBoxList.iterator();
while (i.hasNext()) {
    JCheckBox tmp = i.next();
        if (chckbxSelectAll.isSelected()) {
            tmp.doClick();
        } else {
            tmp.setSelected(false);
            selectedCounter -= 1;
            if (selectedCounter < 0) {
                selectedCounter = 0;
            }
    noOfFileTxt.setText(Integer.toString(selectedCounter));
        }
    }
}




Aucun commentaire:

Enregistrer un commentaire