↓ Skip to main content

Observable Objects

Table of Contents

The “Observer Pattern”
#

The key element in how JavaFX achieves Reactivity is via a set of objects which implement the “Observer Pattern”. Fundamentally, this is a hierarchy of classes which allow you to create an observable wrapper around virtually any data type. Along with that comes all of the structure that you need to connect them to each other so that a change in one observable object triggers changes in other observable objects.

When you are working with Observables, you tend to be concerned with establishing the connections between them. This means that the code that you write is configuration code that happens when the Observables are created. And since almost all of the uses that you’ll have for them in the GUI are expressed via Observables baked into the Nodes, this means that you connect them to the Node Properties and then forget about them.

The Observable library is extensive, extensible and has massive functionality. This means that it can be a challenge to learn how to use it properly.

Just like the Nodes, there are a large number of classes and interfaces that extend from a single parent class. This is the Observable interface. This includes the ObservableList and Property interfaces which are used extensively in just about any JavaFX application.

In this section, we are taking an in-depth look at all things observable in JavaFX. You can get a long way just by reading the first two articles here. If you want to achieve comprehensive understanding about how the entire library hangs together, there are several articles in the section called “Guide to the Observable Classes”.

An Introduction to Properties

·28 mins
If you are a beginner with JavaFX and are wondering, “What are all these Property things anyway?”, then this is the article for you. Besides the Properties themselves, we also cover the basics of using them with Bindings and Listeners. Read this article and you should have a good idea how to start out with JavaFX Properties.

Guide To the Observable Classes

1 min
A three part series (so far) that provides an in-depth examination of all of the classes and interfaces that make up the library of observable types in JavaFX.

Action Properties

·14 mins
There a little known, but very useful function call in most Properties. This can be overridden to turn a Property into a class that transforms a value change into an action.