JavaFX CheckComboBox How to check and uncheck all items when checking or unckeck some of the items.
Uncheck all when unckeck item All
ObservableList<String> list = FXCollections.observableArrayList("All","Item 1", "Item 2", "Item 3", "Item 4");
checkBoxCombo.getItems().addAll(list);
checkBoxCombo.getCheckModel().getCheckedItems().addListener(new ListChangeListener<String>() {
public void onChanged(ListChangeListener.Change<? extends String> c) {
if(checkBoxCombo.getCheckModel().isChecked(0))
checkBoxCombo.getCheckModel().checkAll();
}
});
Add a
boolean
field to the listener to prevent recursion: