An ObservableList lights up change events when items are added and removed from the list, regardless of whether it is created or not using the extractor.
However, if the items in the list are or contain links to observable properties, the list will trigger updates if these properties are changed only if they are constructed using an extractor that returns an array containing links to these properties.
This should demonstrate the difference:
import javafx.beans.Observable; import javafx.beans.property.IntegerProperty; import javafx.beans.property.SimpleIntegerProperty; import javafx.collections.FXCollections; import javafx.collections.ListChangeListener; import javafx.collections.ListChangeListener.Change; import javafx.collections.ObservableList; public class ListExtractorDemo { public static void main(String[] args) { ObservableList<IntegerProperty> listWithoutExtractor = FXCollections.observableArrayList(); ObservableList<IntegerProperty> listWithExtractor = FXCollections.observableArrayList(p -> new Observable[]{p}); listWithoutExtractor.addListener(createListener("listWithoutExtractor")); listWithExtractor.addListener(createListener("listWithExtractor")); IntegerProperty p1 = new SimpleIntegerProperty(1); IntegerProperty p2 = new SimpleIntegerProperty(2);
A typical use case is @kleopatra's answer to the JavaFX 2.0 Choice Box Issue. How to update choiceBox, which presents a list of objects when an object is updated?
source share