Top Description Methods
javafx.beans.binding

public Interface Binding<T>

extends ObservableValue<T>
Known Direct Subinterfaces
javafx.beans.binding.NumberBinding
Known Direct Implementers
javafx.beans.binding.BooleanBinding, javafx.beans.binding.ListBinding, javafx.beans.binding.MapBinding, javafx.beans.binding.ObjectBinding, javafx.beans.binding.SetBinding, javafx.beans.binding.StringBinding
Type Parameters
<T>
the type of the wrapped value
Imports
javafx.beans.value.ObservableValue, javafx.collections.ObservableList

A Binding calculates a value that depends on one or more sources. The sources are usually called the dependency of a binding. A binding observes its dependencies for changes and updates its value automatically.

While a dependency of a binding can be anything, it is almost always an implementation of javafx.beans.value.ObservableValue. Binding implements ObservableValue allowing to use it in another binding. With that one can assemble very complex bindings from simple bindings.

All bindings in the JavaFX runtime are calculated lazily. That means, if a dependency changes, the result of a binding is not immediately recalculated, but it is marked as invalid. Next time the value of an invalid binding is requested, it is recalculated.

It is recommended to use one of the base classes defined in this package (e.g. DoubleBinding) to define a custom binding, because these classes already provide most of the needed functionality. See DoubleBinding for an example.

Since
JavaFX 2.0
See Also
DoubleBinding

Method Summary

Modifier and TypeMethod and Description
public void
dispose()

Signals to the Binding that it will not be used anymore and any references can be removed.

public ObservableList<?>

Returns:

an unmodifiable ObservableList of the dependencies
getDependencies
()

Returns the dependencies of a binding in an unmodifiable javafx.collections.ObservableList.

public void
invalidate()

Mark a binding as invalid.

public boolean

Returns:

true if the Binding is valid, false otherwise
isValid
()

Checks if a binding is valid.

Inherited from javafx.beans.value.ObservableValue:
addListenerflatMapgetValuemaporElseremoveListenersubscribesubscribewhen

Method Detail

disposeback to summary
public void dispose()

Signals to the Binding that it will not be used anymore and any references can be removed. A call of this method usually results in the binding stopping to observe its dependencies by unregistering its listener(s). The implementation is optional.

All bindings in our implementation use instances of javafx.beans.WeakInvalidationListener, which means usually a binding does not need to be disposed. But if you plan to use your application in environments that do not support WeakReferences you have to dispose unused Bindings to avoid memory leaks.

getDependenciesback to summary
public ObservableList<?> getDependencies()

Returns the dependencies of a binding in an unmodifiable javafx.collections.ObservableList. The implementation is optional. The main purpose of this method is to support developers during development. It allows to explore and monitor dependencies of a binding during runtime.

Because this method should not be used in production code, it is recommended to implement this functionality as sparse as possible. For example if the dependencies do not change, each call can generate a new ObservableList, avoiding the necessity to store the result.

Returns:ObservableList<?>

an unmodifiable ObservableList of the dependencies

invalidateback to summary
public void invalidate()

Mark a binding as invalid. This forces the recalculation of the value of the Binding next time it is request.

isValidback to summary
public boolean isValid()

Checks if a binding is valid.

Returns:boolean

true if the Binding is valid, false otherwise