I have the error :
Exception in thread "JavaFX Application Thread" java.lang.IndexOutOfBoundsException: Index: 0
I thought it was because I have to use Platform.runLater(), but it seems the errors does not come from this.
Here's the function that I try to correct with Platform.runLater() :
public void setListAirportForFilter(ListAirport listAirport){
this.myListAirport = listAirport;
departureCheckListView.setItems(myListAirport.getObservableDepartureAirtport());
arrivalCheckListView.setItems(myListAirport.getObservableArrivalAirport());
departureCheckListView.getCheckModel().getCheckedItems().addListener(new ListChangeListener<String>() {
@Override
public void onChanged(ListChangeListener.Change<? extends String> c) {
c.next();
if(c.wasAdded()) {
observableForbiddenDeparture.add(c.getAddedSubList().get(0));
System.out.println("Item Checked : " + c.getAddedSubList().get(0));
}
else if (c.wasRemoved()) {
observableForbiddenDeparture.remove(c.getAddedSubList().get(0));
System.out.println("Item Unchecked : " + c.getRemoved().get(0));
}
}
});
}
The error triggered in the second case, with the removed.
If an element is removed and it calls the
ListChangeListener, then your change will have the list of itemsremovedand not the list of itemsadded.In your second case, you are checking for
c.wasRemoved(), which means if it is true, elements were removed from the ObservableList. All your removed values are stored insidegetRemoved()sub-list and if you try to fetchgetAddedSubList(), you will get an empty list.You need to use
instead of