Java Reference
In-Depth Information
System.out.println("Unbinding otherProperty from intProperty.");
otherProperty.unbind();
System.out.println("otherProperty.get() = " + otherProperty.get());
System.out.println("Calling intProperty.set(8192).");
intProperty.set(8192);
System.out.println("otherProperty.get() = " + otherProperty.get());
}
}
In this example we created a SimpleIntegerProperty object called intProperty with an initial value
of 1024 . We then updated its value through a series of different integers while we added and then removed
an InvalidationListener , added and then removed a ChangeListener , and finally created another
SimpleIntegerProperty named otherProperty , bound it to and then unbound it from intProperty . We have taken
advantage of the Java 8 Lambda syntax in defining our listeners. The sample program used a generous amount of
println calls to show what is happening inside the program.
When we run the program in Listing 4-1, the following output is printed to the console:
intProperty = IntegerProperty [value: 1024]
intProperty.get() = 1024
intProperty.getValue() = 1024
Added invalidation listener.
Calling intProperty.set(2048).
The observable has been invalidated: IntegerProperty [value: 2048].
Calling intProperty.setValue(3072).
The observable has been invalidated: IntegerProperty [value: 3072].
Removed invalidation listener.
Calling intProperty.set(4096).
Added change listener.
Calling intProperty.set(5120).
The observableValue has changed: oldValue = 4096, newValue = 5120
Removed change listener.
Calling intProperty.set(6144).
otherProperty.get() = 0
Binding otherProperty to intProperty.
otherProperty.get() = 6144
Calling intProperty.set(7168).
otherProperty.get() = 7168
Unbinding otherProperty from intProperty.
otherProperty.get() = 7168
Calling intProperty.set(8192).
otherProperty.get() = 7168
By correlating the output lines with the program source code (or by stepping through the code in the debugger of
your favorite IDE), we can draw the following conclusions.
 
Search WWH ::




Custom Search