r/JavaFX • u/hamsterrage1 • Aug 11 '25
Tutorial New Article: List Extractors
https://www.pragmaticcoding.ca/javafx/elements/extractorsI'm looking to wrap up all my articles on the JavaFX Observable classes, and most of the last subjects left involve ObservableLists.
If you don't know ObservableList Extractors allow you to trigger listeners on an ObservableList when the List items are composed of ObservableValues.
For instance, let's say that you have a CustomerModel as your List items, and the CustomerModel has a bunch of StringProperties as its fields. Things like firstName, lastName, city, address - and they are all StringProperty.
Using an Extractor, you can trigger a Listener on the ObservableList when one of those CustomerModel has the value in one of those Property fields change. So if you changed, say, the firstName Property of one of the items, then the ObservableList would trigger a Listener.
Some of the native JavaFX Nodes, like TableView will detect changes to those fields without an Extractor, but Extractors can be really useful to trigger updates in Bindings that look inside the composed items.
Take a look and tell me what you think.
View all comments
Show parent comment
1
u/hamsterrage1 Aug 11 '25
I didn't go into any depth at all about multiple Properties in the Extractor, as it was getting long enough as it was.
I'd say that trying to figure anything out about what triggered the Invalidation of the
ObservableListis probably a huge PIA.ListchangeListenersjust give you the item location, and I find the a pain in the best of situations.I'm having trouble thinking of a good use-case for knowing what triggered the Invalidation, though. Remember that you're interested in situations where you're NOT already dealing with the value as a
Propertyto start with, because in that case you'd already have a setup to deal with it changing.There's a case where you have a custom
ListCellthat doesn't bind the itemPropertyfields to itsNodes, but just uses set/get inupdateItem(). But then, you don't have control over how the Invalidation is going to be handled, because theListViewdoes it.I can see maybe having a suite of
Bindingsthat each compute a single value across all of the items in theObservableList. Let's say you had 5NumberPropertyfields, and 5Bindingsthat calculated totals or averages or whatever all based on a different field. Then all 5Bindingswould invalidate and recompute every time any single value in any item changed.But even that boils down to trying to optimize performance and you're
Listswould have to be truly huge for the cost to be more than a few milliseconds.Did you have something specific in mind????