JavaFX Observables, Bindings and Listeners
Observables, Bindings and Listeners are the key elements supplied by the JavaFX library to create Reactive applications in JavaFX. This is an incredibly complete toolkit, which means that it can also be complicated and difficult to understand. These articles are designed to explain what each of these elements are, and how you can use them to create simple, easy to understand and maintain Reactive applications.
The Beginners Guide to Properties, Listeners and Bindings
The Observable elements of JavaFX can be overwhelming for beginners. In this guide you’ll find a overview of all of the Properties, Bindings and Listener types and see how to use them to create Reactive JavaFX applications
Observables and Properties
The Complete Guide to the Observable Types
The articles on this page comprise a comprehensive look at all of the interfaces and classes in the Observables hierarchy. Look here if you want an in-depth understanding of how all of these types fit together and work together.
Action Properties
Properties don’t just have to be observable wrappers for values. You can use the invalidated()
method to create a Property that takes an action whenever it’s value changes.
New Observable Methods
JavaFX versions 19 and 21 gave us new methods for dealing with Observables. We now have ObservableValue.map(), and variations on ObservableValue.subscribe(). These new methods should be your “go to” approach to Listeners and Bindings from now on.
Bindings:
Bindings
are ObservableValues
that are tied to one or more other ObservableValues
. This means that they are automatically updated when any one of those other ObservableValues
changes. This allows you to define your application in terms of relationships between dynamic values which is the key to building Reactive applications.
All About Custom Bindings
The key to understanding how Bindings work is to understand how to create your own Binding by extending one of the abstract classes from the JavaFX library.
How To Use the Bindings Class
The Bindings class is a static library of methods that can create bindings for you. Learning how to use this library will give you the ability to create all kinds of special bindings without having to create custom binding classes.
Conditional Bindings
Bindings don’t just have to be simple evaluations based on the current values of their dependencies. Here’s how to create Bindings with internal state that allows them to do some very sophisticated things
Listeners:
ChangeListeners and InvalidationListeners
Which kind of Listener should you use, and when?
Listeners, Events and Bindings
It can be confusing how to know where you should use a Listener, where you should use a Binding, or whether it might be better to implement an EventHandler. This article looks at the differences between these things, and when it’s best to use each one.