I try to work with Controls FX and the Check List View component, but I have several issues on how to use it :
- By default, cell are not selected when I add item in the
CheckListView
, how can I do to have it selected by default ? I think I have to use setCheckModel but I'm lost. - How can I handle an event when someone click on a
checkBox
? I don't know what to do, because event that I handle are on the node but not on thecheckBox
. I don't understand how to use theeventHandler
with this component.
EDIT : Here's what I do :
departureCheckListView.setItems(myListAirport.getObservableDepartureAirtport());
departureCheckListView.getItems().addListener(new ListChangeListener<String>() {
@Override
public void onChanged(Change<? extends String> c) {
c.next();
if (c.wasAdded()) {
System.out.println(c.getAddedSubList().get(0));
//departureCheckListView.getSelectionModel().select(c.getAddedSubList().get(0));
Platform.runLater(new Runnable() {
@Override
public void run() {
departureCheckListView.getCheckModel().check(c.getAddedSubList().get(0));
}
});
}
}
});
The first item that I add is checked, but the followed items.
I don't know if this could helps, but my list is sorted.
For your first case, use a Listener on
the List of Items
in theCheckListView
, to check if an item is added to it or nor, then, use thegetSelectionModel().select(<Item>)
to select it.For the second case, use
getCheckModel().getCheckedItems()
to get the List of Items that havechecked values
. Similarly, check if a an item has beenadded / removed
from the list.Complete MCVE - Tested with ControlsFX - 8.40.9
Update : For checking the new added item check-box, instead of selecting
Use :
instead of
If you want it to be checked and at the same time selected, you can use
both of them
.