I noticed that itemsProperty in ListView
is of type ObjectProperty<ObservableList<T>>
, but I would have expected ListProperty<T>
.
Now I wonder: When should I Use ObjectProperty<ObservableList<T>>
, and when ListProperty<T>
?
The answer can be found in the JavaFX documentation for ObjectProperty, specifically this line:
For specialized implementations for ObservableList, ObservableSet and ObservableMap that also report changes inside the collections, see ListProperty, SetProperty and MapProperty, respectively.
So using ObjectProperty<ObservableList<T>>
will report if the ObservableList
itself changes, but not if any members within that ObservableList
are changed.
So, to answer your question, you would use ObjectProperty<ObservableList<T>>
when you only need to be reported if the ObservableList
has changed (ie: items added or deleted). You should use ListProperty<T>
if you also need to track changes made to the actual items within that ObservableList
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With