Working with the Property API
In addition to the regular getters and setters, JavaFX provides a Property API to almost all its classes' fields.
For example, there are the following methods to work with the Stage
title:
String getTitle(); //getter void setTitle(String title); //setter StringProperty titleProperty(); //property access
Technically, getters and setters are not required, and the Property
value can be used all the time.
The Property
class has the following two important APIs—Observable and Binding.
Using the Observable API
An Observable
is an interface which allows you to subscribe to the change event of the corresponding property. All JavaFX properties are observable, thus you can track changes of every small parameter of every JavaFX node using the Observable API.
Let's take a look at the next simple example, which dynamically updates the width of the JavaFX application's window.
The window, represented by the Stage
class, has a property called widthProperty
, which...