Java Reference
In-Depth Information
defining JavaFX components. We talk about the JavaFX Beans getter, setter, and property getter naming convention
later in this chapter, after we have covered the key concepts and interfaces of the JavaFX properties and bindings
framework.
Another strand of heritage of the JavaFX properties and bindings framework comes from the JavaFX Script
language that was part of the JavaFX 1.x platform. Although the JavaFX Script language was deprecated in the JavaFX
platform in favor of a Java-based API, one of the goals of the transition was to preserve most of the powers of the
JavaFX Script's
bind
keyword, the expressive power of which has delighted many JavaFX enthusiasts. As an example,
JavaFX Script supports the binding to complex expressions:
var a = 1;
var b = 10;
var m = 4;
def c = bind for (x in [a..b] where x < m) { x * x };
This code will automatically recalculate the value of
c
whenever the values of
a
,
b
, or
m
are changed.
Although the JavaFX properties and bindings framework does not support all of the binding constructs of JavaFX
Script, it supports the binding of many useful expressions. We talk more about constructing compound binding
expressions after we cover the key concepts and interfaces of the framework.
A Motivating Example
Let's start with an example in Listing 4-1 that shows off the capabilities of the
Property
interface through the use of a
couple of instances of the
SimpleIntegerProperty
class.
Listing 4-1.
MotivatingExample.java
import javafx.beans.InvalidationListener;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
public class MotivatingExample {
private static IntegerProperty intProperty;
public static void main(String[] args) {
createProperty();
addAndRemoveInvalidationListener();
addAndRemoveChangeListener();
bindAndUnbindOnePropertyToAnother();
}
private static void createProperty() {
System.out.println();
intProperty = new SimpleIntegerProperty(1024);
System.out.println("intProperty = " + intProperty);
System.out.println("intProperty.get() = " + intProperty.get());
System.out.println("intProperty.getValue() = " + intProperty.getValue().intValue());
}
Search WWH ::
Custom Search