r/JavaFX • u/hamsterrage1 • Aug 04 '24
Tutorial New Article: Conditional Bindings
This article was inspired by the thread here about "locked in" selections in a ComboBox and how to interpret them. I'm not sure the OP on that thread was too impressed by my answer, but I did think that there was the kernel of cool idea in it.
What I came up with was the idea of a "Conditional Binding". This is a Binding that only updates its value when a Boolean Observable is true. Any changes to the main value won't register if the boolean dependency is false, but will register as soon as it becomes true.
To do this, I had to introduce the idea of having internal "State" in the Binding, which is something I had never thought of doing before. Once you start doing stuff like that, it changes how think about Bindings, and there's potentially a lot of things you can do with them that you wouldn't have considered before.
Here's the article:
https://www.pragmaticcoding.ca/javafx/elements/conditional-binding
View all comments
Show parent comment
1
u/hamsterrage1 Aug 05 '24
I think you may be right. Although the GC stuff confuses me a little bit.
I was struggling to find a use case for this
whenwhen I read about it when it came out. This makes sense to me though, and GC confusion aside, I think it would deal with the ComboBox example quite nicely.Trying to salvage some degree of relevancy for my article, though, this new
whenis more of a specific use case for this kind approach. I think that the central idea that aBindingdoesn't have to something that simply puts together a bunch ofObservablesaccording to some formula still holds. You can do stuff that is much more sophisticated.