Skip to main content

Guide To the Observable Classes

Note

This is not a beginners subject. You’ll just be scared away from Reactive JavaFX if you read this article as your introduction to Properties and Bindings.

If you have ever wondered, “What’s the difference between ObservableValue and ObservableObjectValue?”, or “When and how should I use ReadOnlyObjectProperty?”, or “What’s a ReadOnlyObjectWrapper?”, then this is the series for you to read.

I spent hours and hours pouring over all of the JavaDocs and the source code for pretty much all of the JavaFX observable types (interfaces and classes) to figure out how they relate to each other and what they do. I don’t think that you’ll find a similar analysis anywhere else, and I think it can be quite valuable whenever you’re attempting to do something a bit more complex with JavaFX, especially if you venture into creating your own custom observable classes.

Guide To the Observable Classes - Part I

The place to start looking at the Observable types is with the generic classes and interfaces. These are the observable wrappers that you can use around any other class of object.

More importantly, the hierarchy here is exactly the same as the hierarchy that is used for all of the typed observables. If you can understand how generic observable classes and interfaces relate to each other, without worrying about what kind of data is inside them, and special classes added to handle those types, then you’ll automatically be able to understand how they work when they are typed.

Guide To the Observable Classes - Part II

This article is about the all of the typed observable classes and interfaces except the ones concerned with List.

You’ll find that all of the relationships and structure found in the generic classes is just about exactly the same, but then there are a few extra classes and interfaces added to the hierarchy depending on the type of data that they hold. We’ll concentrate mostly on two types, String and Integer here, because dealing with the others would just be redundant. String is typical of stand-alone types, and Integer is typical of types that are included in Number.

Guide To the Observable Classes - Part III

You can work with a JavaFX for a long time before you realize that ListProperty is even a thing. And when you do, you’ll probably be extremely confused by it.

That’s because ListProperty (and all of the other types that descend from ObservableValue<List>) implements all of the methods of ObservableList as well as everything implied by ObservableValue and its descendants. This is a little mind boggling, because ObservableList<T> is generic itself, and implements everything in List<T>, and this means that ListProperty<T> does everything that Property<T> does, as well as everything that ObservableList<T> and, therefore, List<T> does.

But don’t worry, read this and it will all make sense - and actually be really useful.