Class Bindings
Usually there are two possibilities to define the same operation: the Fluent
API and the the factory methods in this class. This allows a developer to
define complex expression in a way that is most easy to understand. For
instance the expression result = a*b + c*d can be defined using only
the Fluent API:
DoubleBinding result = a.multiply(b).add(c.multiply(d));
Or using only factory methods in Bindings:
NumberBinding result = add (multiply(a, b), multiply(c,d));
Or mixing both possibilities:
NumberBinding result = add (a.multiply(b), c.multiply(d));
The main difference between using the Fluent API and using the factory
methods in this class is that the Fluent API requires that at least one of
the operands is an Expression (see javafx.beans.binding). (Every
Expression contains a static method that generates an Expression from an
ObservableValue.)
Also if you watched closely, you might have noticed that the return type of
the Fluent API is different in the examples above. In a lot of cases the
Fluent API allows to be more specific about the returned type (see
NumberExpression for more details about implicit
casting.
- Since:
- JavaFX 2.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic BooleanBindingand(ObservableBooleanValue op1, ObservableBooleanValue op2) Creates aBooleanBindingthat calculates the conditional-AND operation on the value of two instance ofObservableBooleanValue.static <T> voidbindBidirectional(Property<String> stringProperty, Property<T> otherProperty, StringConverter<T> converter) Generates a bidirectional binding (or "bind with inverse") between aString-Propertyand anotherPropertyusing the specifiedStringConverterfor conversion.static <T> voidbindBidirectional(Property<T> property1, Property<T> property2) Generates a bidirectional binding (or "bind with inverse") between two instances ofProperty.static BooleanBindingcreateBooleanBinding(Callable<Boolean> func, Observable... dependencies) Helper function to create a customBooleanBinding.static NumberBindingdivide(ObservableNumberValue op1, int op2) Creates a newNumberBindingthat calculates the division of the value of aObservableNumberValueand a constant value.static BooleanBindingstatic <E> BooleanBindingisEmpty(ObservableList<E> op) static BooleanBindingstatic BooleanBindingCreates aBooleanBindingthat calculates the inverse of the value of aObservableBooleanValue.static BooleanBindingor(ObservableBooleanValue op1, ObservableBooleanValue op2) Creates aBooleanBindingthat calculates the conditional-AND operation on the value of two instance ofObservableBooleanValue.static voidunbindBidirectional(Object property1, Object property2) Delete a bidirectional binding that was previously defined withbindBidirectional(Property, Property)or.invalid @link
#bindBidirectional(javafx.beans.property.Property, javafx.beans.property.Property, java.text.Format)static <T> voidunbindBidirectional(Property<T> property1, Property<T> property2) Delete a bidirectional binding that was previously defined withbindBidirectional(Property, Property).
-
Method Details
-
createBooleanBinding
public static BooleanBinding createBooleanBinding(Callable<Boolean> func, Observable... dependencies) Helper function to create a customBooleanBinding.- Parameters:
func- The function that calculates the value of this bindingdependencies- The dependencies of this binding- Returns:
- The generated binding
- Since:
- JavaFX 2.1
-
not
Creates aBooleanBindingthat calculates the inverse of the value of aObservableBooleanValue.- Parameters:
op- theObservableBooleanValue- Returns:
- the new
BooleanBinding - Throws:
NullPointerException- if the operand isnull
-
bindBidirectional
Generates a bidirectional binding (or "bind with inverse") between two instances ofProperty.A bidirectional binding is a binding that works in both directions. If two properties
aandbare linked with a bidirectional binding and the value ofachanges,bis set to the same value automatically. And vice versa, ifbchanges,ais set to the same value.A bidirectional binding can be removed with
unbindBidirectional(Property, Property).Note: this implementation of a bidirectional binding behaves differently from all other bindings here in two important aspects. A property that is linked to another property with a bidirectional binding can still be set (usually bindings would throw an exception). Secondly bidirectional bindings are calculated eagerly, i.e. a bound property is updated immediately.
- Type Parameters:
T- the types of the properties- Parameters:
property1- the firstProperty<T>property2- the secondProperty<T>- Throws:
NullPointerException- if one of the properties isnullIllegalArgumentException- if both properties are equal
-
unbindBidirectional
Delete a bidirectional binding that was previously defined withbindBidirectional(Property, Property).- Type Parameters:
T- the types of the properties- Parameters:
property1- the firstProperty<T>property2- the secondProperty<T>- Throws:
NullPointerException- if one of the properties isnullIllegalArgumentException- if both properties are equal
-
unbindBidirectional
Delete a bidirectional binding that was previously defined withbindBidirectional(Property, Property)or.invalid @link
#bindBidirectional(javafx.beans.property.Property, javafx.beans.property.Property, java.text.Format)- Parameters:
property1- the firstProperty<T>property2- the secondProperty<T>- Throws:
NullPointerException- if one of the properties isnullIllegalArgumentException- if both properties are equal- Since:
- JavaFX 2.1
-
bindBidirectional
public static <T> void bindBidirectional(Property<String> stringProperty, Property<T> otherProperty, StringConverter<T> converter) Generates a bidirectional binding (or "bind with inverse") between aString-Propertyand anotherPropertyusing the specifiedStringConverterfor conversion.A bidirectional binding is a binding that works in both directions. If two properties
aandbare linked with a bidirectional binding and the value ofachanges,bis set to the same value automatically. And vice versa, ifbchanges,ais set to the same value.A bidirectional binding can be removed with
unbindBidirectional(Object, Object).Note: this implementation of a bidirectional binding behaves differently from all other bindings here in two important aspects. A property that is linked to another property with a bidirectional binding can still be set (usually bindings would throw an exception). Secondly bidirectional bindings are calculated eagerly, i.e. a bound property is updated immediately.
- Parameters:
stringProperty- theStringPropertyotherProperty- the other (non-String)Propertyconverter- theStringConverterused to convert between the properties- Throws:
NullPointerException- if one of the properties or theconverterisnullIllegalArgumentException- if both properties are equal- Since:
- JavaFX 2.1
-
and
Creates aBooleanBindingthat calculates the conditional-AND operation on the value of two instance ofObservableBooleanValue.- Parameters:
op1- firstObservableBooleanValueop2- secondObservableBooleanValue- Returns:
- the new
BooleanBinding - Throws:
NullPointerException- if one of the operands isnull
-
or
Creates aBooleanBindingthat calculates the conditional-AND operation on the value of two instance ofObservableBooleanValue.- Parameters:
op1- firstObservableBooleanValueop2- secondObservableBooleanValue- Returns:
- the new
BooleanBinding - Throws:
NullPointerException- if one of the operands isnull
-
divide
Creates a newNumberBindingthat calculates the division of the value of aObservableNumberValueand a constant value.- Parameters:
op1- the constant valueop2- theObservableNumberValue- Returns:
- the new
NumberBinding - Throws:
NullPointerException- if theObservableNumberValueisnull
-
isEmpty
- Type Parameters:
E- type of theListelements- Parameters:
op- theObservableList- Returns:
- the new
BooleanBinding - Throws:
NullPointerException- if theObservableListisnull- Since:
- JavaFX 2.1
-
isEmpty
Creates a newBooleanBindingthat holdstrueif the value of aObservableStringValueis empty.Note: In this comparison a
Stringthat isnullis considered to be empty.- Parameters:
op- theObservableStringValue- Returns:
- the new
BooleanBinding - Throws:
NullPointerException- if theObservableStringValueisnull- Since:
- JavaFX 8.0
-
isNotEmpty
Creates a newBooleanBindingthat holdstrueif the value of aObservableStringValueis not empty.Note: In this comparison a
Stringthat isnullis considered to be empty.- Parameters:
op- theObservableStringValue- Returns:
- the new
BooleanBinding - Throws:
NullPointerException- if theObservableStringValueisnull- Since:
- JavaFX 8.0
-