samedi 12 mai 2018

How to refresh a JavaFX ListView of CheckBoxes and keep their CheckedProperty?

How can i refresh this JFXListView when the ArrayList R.OffrirService() changes and keep the CheckedProperty of JFXCheckBoxes ?

This is my code:

@FXML
private JFXListView li_se;

int d;

@FXML
private void Services(ActionEvent e) {
try {
    li_se.getItems().clear();
    for (int i = 0; i < R.OffrirService().size(); i++) {
        JFXCheckBox s = new JFXCheckBox(R.OffrirService().get(i));
        s.selectedProperty().addListener((obs, wasOn, isNowOn) -> {
            if (wasOn == false) {
                //if checked do something
                d++;
                    if (d == R.OffrirService().size()) {
                        //if all checked do something
                    }
            } else {
                //if unchecked do something
                d--;
                    if (d == 0) {
                        //if all unchecked do something
                    }
            //System.out.println(s.getText() + " changed on state from " + wasOn + " to " + isNowOn);
        });
        li_se.getItems().add(s);
}

}




Aucun commentaire:

Enregistrer un commentaire