Slightly adapted code from example shown at stackoverflow.com.
Reference:
- Stackoverflow. Custom Bidirectional Bindings in JavaFX, Copyright BlackLabrador, CC BY-SA 4.0 license
- stackoverflow.com
- Author:
- BlackLabrador (as stated in the reference)
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T,M> void bind(javafx.beans.property.Property<T> propertyA, javafx.beans.property.Property<M> mediatorB, Function<M, javafx.beans.value.ObservableValue<T>> propertyB) Binds property 'a' to property 'b'.static <T,M> void bind(javafx.beans.property.Property<T> propertyA, javafx.beans.property.Property<M> mediatorB, Function<M, javafx.beans.value.ObservableValue<T>> propertyB, T unboundValue) Binds property 'a' to property 'b'.static <T,M> void bind(javafx.beans.value.ObservableValue<M> mediatorA, Function<M, javafx.beans.property.Property<T>> propertyA, javafx.beans.value.ObservableValue<T> propertyB, T unboundValue) Binds property 'a' to property 'b'.static <T,M> void bindBidirectional(javafx.beans.property.Property<T> propertyA, javafx.beans.property.Property<M> mediator, Function<M, javafx.beans.property.Property<T>> propertyB) Binds property 'a' to property 'b'.static <T,S> void bindBidirectional(javafx.beans.property.StringProperty propertyA, javafx.beans.property.Property<S> mediator, Function<S, javafx.beans.property.Property<T>> propertyB, javafx.util.StringConverter<T> stringConverter) Binds property 'a' to property 'b'.static <A,B, PROPERTY_A extends javafx.beans.value.WritableValue<A> & javafx.beans.value.ObservableValue<A>, PROPERTY_B extends javafx.beans.value.WritableValue<B> & javafx.beans.value.ObservableValue<B>>
voidbindBidirectionalAndConvert(PROPERTY_A propertyA, PROPERTY_B propertyB, Function<A, B> convertAtoB, Function<B, A> convertBtoA) Creates a bidirectional binding for properties A and B using the provided conversion functions.static <T,M> void bindBidirectionalStrongly(javafx.beans.property.Property<T> propertyA, javafx.beans.property.Property<M> mediator, Function<M, javafx.beans.property.Property<T>> propertyB) Binds property 'a' to property 'b'.static <T,M> void bindBidirectionalStrongly2(javafx.beans.property.Property<T> propertyA, javafx.beans.property.Property<M> mediator, Function<M, javafx.beans.property.Property<T>> propertyB) static <D,S> void bindContent(javafx.collections.ObservableList<D> dest, javafx.collections.ObservableList<S> src, Function<S, D> toDest) Binds list dest to list source.static <D,S> void bindContent(javafx.collections.ObservableList<D> dest, javafx.collections.ObservableList<S> src, Function<S, D> toDest, @Nullable Consumer<D> destOnRemove) Binds list dest to list source.static <D,S> void bindContentBidirectional(javafx.collections.ObservableList<D> dest, javafx.collections.ObservableList<S> src, Function<S, D> toDest, @Nullable Consumer<D> destOnRemove, Function<D, S> toSource, @Nullable Consumer<S> sourceOnRemove) Binds list dest to list source bidirectionally.static <E,T> void bindElements(javafx.collections.ObservableList<E> list, BiConsumer<E, T> setter, T value) Sets the specified value to all elements of the list.static <E,T> void bindElements(javafx.collections.ObservableList<E> list, Function<E, javafx.beans.property.Property<T>> getter, javafx.beans.binding.Binding<T> binding) Binds the specified property of all list elements to the given binding.static <E,T> void bindElements(javafx.collections.ObservableList<E> list, Function<E, javafx.beans.property.Property<T>> getter, javafx.beans.binding.Binding<T> binding, T unboundValue) Binds the specified property of all list elements to the given binding.static <E,T> void bindElements(javafx.collections.ObservableList<E> list, Function<E, javafx.beans.property.Property<T>> getter, javafx.beans.property.Property<T> property) Binds the specified property of all list elements to the given property.static <E,T> void bindElements(javafx.collections.ObservableList<E> list, Function<E, javafx.beans.property.Property<T>> getter, javafx.beans.property.Property<T> property, T unboundValue) Binds the specified property of all list elements to the given property.static <D,S> void bindListContentToSet(javafx.collections.ObservableList<D> dest, javafx.collections.ObservableSet<S> src, Function<S, D> toDest) Binds list dest to set source.static <D,S> void bindListContentToSet(javafx.collections.ObservableList<D> dest, javafx.collections.ObservableSet<S> src, Function<S, D> toDest, Consumer<D> disposeDest) static <E> voidbindMembershipToBoolean(javafx.collections.ObservableSet<E> set, E element, javafx.beans.value.ObservableValue<Boolean> value) Adds or removes an element from a set depending on the bound boolean value.static <T> javafx.beans.binding.ObjectBinding<T> Creates a binding with a computed value.static javafx.beans.binding.DoubleBindingcomputeDouble(DoubleSupplier op, javafx.beans.value.ObservableValue<?>... dependendies) Creates a binding with a computed value.static <A,B> javafx.beans.binding.ObjectBinding <B> Creates a binding with a converted value.static javafx.beans.binding.StringExpressionReturns a string expression which usesjava.test.MessageFormatto format the text.static <D,S> void unbindListContentToSet(javafx.collections.ObservableList<D> dest, javafx.collections.ObservableSet<S> src) Unbinds list dest from set source.static <A,B> javafx.beans.value.ObservableValue <B> via(javafx.beans.value.ObservableValue<A> root, Function<A, javafx.beans.value.ObservableValue<B>> step) Creates a binding to get a propertya.b.static <A,B, C> javafx.beans.value.ObservableValue <C> via(javafx.beans.value.ObservableValue<A> root, Function<A, javafx.beans.value.ObservableValue<B>> stepB, Function<B, javafx.beans.value.ObservableValue<C>> stepC) Creates a binding to get an observable valuea.b.c.static <A,B, C, D>
javafx.beans.value.ObservableValue<D> via(javafx.beans.value.ObservableValue<A> root, Function<A, javafx.beans.value.ObservableValue<B>> stepB, Function<B, javafx.beans.value.ObservableValue<C>> stepC, Function<C, javafx.beans.value.ObservableValue<D>> stepD) Creates a binding to get an observable valuea.b.c.d.static <A,B> javafx.beans.property.Property <B> viaBidirectional(javafx.beans.value.ObservableValue<A> root, Function<A, javafx.beans.property.Property<B>> step) Creates a binding to get a propertya.b.static <A,B, C> javafx.beans.property.Property <C> viaBidirectional(javafx.beans.value.ObservableValue<A> root, Function<A, javafx.beans.value.ObservableValue<B>> stepB, Function<B, javafx.beans.property.Property<C>> stepC) Creates a binding to get a propertya.b.c.static <A,B, C, D>
javafx.beans.property.Property<D> viaBidirectional(javafx.beans.value.ObservableValue<A> root, Function<A, javafx.beans.value.ObservableValue<B>> stepB, Function<B, javafx.beans.value.ObservableValue<C>> stepC, Function<C, javafx.beans.property.Property<D>> stepD) Creates a binding to get a propertya.b.c.d.
-
Method Details
-
bindBidirectionalStrongly
public static <T,M> void bindBidirectionalStrongly(javafx.beans.property.Property<T> propertyA, javafx.beans.property.Property<M> mediator, Function<M, javafx.beans.property.Property<T>> propertyB) Binds property 'a' to property 'b'. Property b is provided by 'mediator'.This method keeps a strong reference to
propertyB.- Type Parameters:
T- the type of properties 'a' and 'b'M- the type of the mediator property- Parameters:
propertyA- property 'a'mediator- the mediator property 'm'propertyB- property 'b', this can be a new instance on each call
-
bindBidirectionalStrongly2
public static <T,M> void bindBidirectionalStrongly2(javafx.beans.property.Property<T> propertyA, javafx.beans.property.Property<M> mediator, Function<M, javafx.beans.property.Property<T>> propertyB) -
bindBidirectional
public static <T,M> void bindBidirectional(javafx.beans.property.Property<T> propertyA, javafx.beans.property.Property<M> mediator, Function<M, javafx.beans.property.Property<T>> propertyB) Binds property 'a' to property 'b'. Property b is provided by 'mediator'.- Type Parameters:
T- the type of properties 'a' and 'b'M- the type of the mediator property- Parameters:
propertyA- property 'a'mediator- the mediator property 'm'propertyB- property 'b', must return the same instance each time when called for the same object 'm'.
-
bind
public static <T,M> void bind(javafx.beans.property.Property<T> propertyA, javafx.beans.property.Property<M> mediatorB, Function<M, javafx.beans.value.ObservableValue<T>> propertyB) Binds property 'a' to property 'b'. Property 'b' is provided by 'mediatorB'.When 'a' is unbound from 'b', its value is set to the value that 'a' had, when this method was invoked.
- Type Parameters:
T- the type of properties 'a' and 'b'M- the type of the mediator property- Parameters:
propertyA- property 'a'mediatorB- the mediator propertypropertyB- property 'b'
-
bind
public static <T,M> void bind(javafx.beans.property.Property<T> propertyA, javafx.beans.property.Property<M> mediatorB, Function<M, javafx.beans.value.ObservableValue<T>> propertyB, T unboundValue) Binds property 'a' to property 'b'. Property 'b' is provided by 'mediatorB'.When 'a' is unbound from 'b', its value is set to 'unboundValue'.
- Type Parameters:
T- the type of properties 'a' and 'b'M- the type of the mediator property- Parameters:
propertyA- property 'a'mediatorB- the mediator propertypropertyB- property 'b'unboundValue- the value to be set on 'a' when 'a' is unbound from 'b'.
-
bind
public static <T,M> void bind(javafx.beans.value.ObservableValue<M> mediatorA, Function<M, javafx.beans.property.Property<T>> propertyA, javafx.beans.value.ObservableValue<T> propertyB, T unboundValue) Binds property 'a' to property 'b'. Property 'a' is provided by 'mediatorA'.When 'a' is unbound from 'b', its value is set to 'unboundValue'.
- Type Parameters:
T- the type of properties 'a' and 'b'M- the type of the mediator property- Parameters:
mediatorA- the mediator propertypropertyA- property 'a'propertyB- property 'b'unboundValue- the value to be set on 'a' when 'a' is unbound from 'b'.
-
bindBidirectional
public static <T,S> void bindBidirectional(javafx.beans.property.StringProperty propertyA, javafx.beans.property.Property<S> mediator, Function<S, javafx.beans.property.Property<T>> propertyB, javafx.util.StringConverter<T> stringConverter) Binds property 'a' to property 'b'. Property b is provided by 'mediator'.- Type Parameters:
T- the value type of property 'b'S- the value type of the mediator property- Parameters:
propertyA- property 'a'mediator- the mediator propertypropertyB- property 'b'stringConverter- the converter
-
bindBidirectionalAndConvert
public static <A,B, void bindBidirectionalAndConvertPROPERTY_A extends javafx.beans.value.WritableValue<A> & javafx.beans.value.ObservableValue<A>, PROPERTY_B extends javafx.beans.value.WritableValue<B> & javafx.beans.value.ObservableValue<B>> (PROPERTY_A propertyA, PROPERTY_B propertyB, Function<A, B> convertAtoB, Function<B, A> convertBtoA) Creates a bidirectional binding for properties A and B using the provided conversion functions.- Type Parameters:
A- the type of value AB- the type of value BPROPERTY_A- the type of property APROPERTY_B- the type of property B- Parameters:
propertyA- property ApropertyB- property BconvertAtoB- converts a value from A to BconvertBtoA- converts a value from B to A
-
formatted
Returns a string expression which usesjava.test.MessageFormatto format the text. SeeMessageStringFormatterfor special treatment of boolean values.- Parameters:
format- The format string.args- The arguments.- Returns:
- The string expression
-
bindContent
public static <D,S> void bindContent(javafx.collections.ObservableList<D> dest, javafx.collections.ObservableList<S> src, Function<S, D> toDest) Binds list dest to list source.- Type Parameters:
D- the type of list destS- the type of list source- Parameters:
dest- list destsrc- list sourcetoDest- mapping function to dest
-
bindContent
public static <D,S> void bindContent(javafx.collections.ObservableList<D> dest, javafx.collections.ObservableList<S> src, Function<S, D> toDest, @Nullable Consumer<D> destOnRemove) Binds list dest to list source.- Type Parameters:
D- the type of list destS- the type of list source- Parameters:
dest- list destsrc- list sourcetoDest- mapping function to destdestOnRemove- this consumer is called when an element is removed from the dest list
-
bindContentBidirectional
public static <D,S> void bindContentBidirectional(javafx.collections.ObservableList<D> dest, javafx.collections.ObservableList<S> src, Function<S, D> toDest, @Nullable Consumer<D> destOnRemove, Function<D, S> toSource, @Nullable Consumer<S> sourceOnRemove) Binds list dest to list source bidirectionally.- Type Parameters:
D- the type of list destS- the type of list source- Parameters:
dest- list destsrc- list sourcetoDest- mapping function to destdestOnRemove- this consumer is called when an element is removed from the dest list
-
bindListContentToSet
public static <D,S> void bindListContentToSet(javafx.collections.ObservableList<D> dest, javafx.collections.ObservableSet<S> src, Function<S, D> toDest) Binds list dest to set source.- Type Parameters:
D- the type of list destS- the type of list source- Parameters:
dest- list destsrc- list sourcetoDest- mapping function to dest
-
bindListContentToSet
-
unbindListContentToSet
public static <D,S> void unbindListContentToSet(javafx.collections.ObservableList<D> dest, javafx.collections.ObservableSet<S> src) Unbinds list dest from set source.- Type Parameters:
D- the type of list destS- the type of list source- Parameters:
dest- list destsrc- list source
-
bindElements
public static <E,T> void bindElements(javafx.collections.ObservableList<E> list, Function<E, javafx.beans.property.Property<T>> getter, javafx.beans.property.Property<T> property) Binds the specified property of all list elements to the given property.If an element is added, its property is bound.
If an element is removed, its property is unbound and the property value is set to null.
- Type Parameters:
E- the element typeT- the property type- Parameters:
list- the listgetter- the getter for the element propertyproperty- the property to which the element properties shall be bound
-
bindElements
public static <E,T> void bindElements(javafx.collections.ObservableList<E> list, Function<E, javafx.beans.property.Property<T>> getter, javafx.beans.property.Property<T> property, T unboundValue) Binds the specified property of all list elements to the given property.If an element is added, its property is bound.
If an element is removed, its property is unbound and the property value is set to
unboundValue.- Type Parameters:
E- the element typeT- the property type- Parameters:
list- the listgetter- the getter for the element propertyproperty- the property to which the element properties shall be boundunboundValue- the value to that is set when the property is unbound.
-
bindElements
public static <E,T> void bindElements(javafx.collections.ObservableList<E> list, Function<E, javafx.beans.property.Property<T>> getter, javafx.beans.binding.Binding<T> binding) Binds the specified property of all list elements to the given binding.If an element is added, its property is bound.
If an element is removed, its property is unbound and the property value is set to null.
- Type Parameters:
E- the element typeT- the property type- Parameters:
list- the listgetter- the getter for the element propertybinding- the binding to which the element properties shall be bound
-
bindElements
public static <E,T> void bindElements(javafx.collections.ObservableList<E> list, Function<E, javafx.beans.property.Property<T>> getter, javafx.beans.binding.Binding<T> binding, T unboundValue) Binds the specified property of all list elements to the given binding.If an element is added, its property is bound.
If an element is removed, its property is unbound and the property value is set to
unboundValue.- Type Parameters:
E- the element typeT- the property type- Parameters:
list- the listgetter- the getter for the element propertybinding- the binding to which the element properties shall be bound
-
bindElements
public static <E,T> void bindElements(javafx.collections.ObservableList<E> list, BiConsumer<E, T> setter, T value) Sets the specified value to all elements of the list.If an element is added, the specified value is set.
If an element is removed, the null value is set.
- Type Parameters:
E- the element typeT- the value type- Parameters:
list- the listsetter- the setter for the value on the elementvalue- the value
-
bindMembershipToBoolean
public static <E> void bindMembershipToBoolean(javafx.collections.ObservableSet<E> set, E element, javafx.beans.value.ObservableValue<Boolean> value) Adds or removes an element from a set depending on the bound boolean value.- Type Parameters:
E- the element type- Parameters:
set- a setelement- an element that is added on true and removed on falsevalue- the boolean value
-
computeDouble
public static javafx.beans.binding.DoubleBinding computeDouble(DoubleSupplier op, javafx.beans.value.ObservableValue<?>... dependendies) Creates a binding with a computed value.If the value of one of the dependencies changes, the binding is marked as invalid.
- Parameters:
op- the operation that computes the valuedependendies- the depencies that invalidate the computed value- Returns:
- a new binding
-
compute
public static <T> javafx.beans.binding.ObjectBinding<T> compute(Supplier<T> op, javafx.beans.value.ObservableValue<?>... dependencies) Creates a binding with a computed value.If the value of one of the dependencies changes, the binding is marked as invalid.
- Type Parameters:
T- the type of the value- Parameters:
op- the operation that computes the valuedependencies- the depencies that invalidate the computed value- Returns:
- a new binding
-
convert
public static <A,B> javafx.beans.binding.ObjectBinding<B> convert(javafx.beans.value.ObservableValue<A> a, Function<A, B> convert) Creates a binding with a converted value.If the value of one of the dependencies changes, the binding is marked as invalid.
- Type Parameters:
A- the type of the valueB- the type of the converted binding- Parameters:
a- the property Aconvert- the conversion function from A to B- Returns:
- a new binding
-
via
public static <A,B> javafx.beans.value.ObservableValue<B> via(javafx.beans.value.ObservableValue<A> root, Function<A, javafx.beans.value.ObservableValue<B>> step) Creates a binding to get a propertya.b.- Type Parameters:
A- the type ofaB- the type ofb- Parameters:
root- observable valueastep- the function that getsa.b- Returns:
- the binding
a.b.
-
via
public static <A,B, javafx.beans.value.ObservableValue<C> viaC> (javafx.beans.value.ObservableValue<A> root, Function<A, javafx.beans.value.ObservableValue<B>> stepB, Function<B, javafx.beans.value.ObservableValue<C>> stepC) Creates a binding to get an observable valuea.b.c.- Type Parameters:
A- the type ofaB- the type ofbC- the type ofc- Parameters:
root- observable valueastepB- the function that getsa.bstepC- the function that getsb.c- Returns:
- the binding
a.b.c.
-
via
public static <A,B, javafx.beans.value.ObservableValue<D> viaC, D> (javafx.beans.value.ObservableValue<A> root, Function<A, javafx.beans.value.ObservableValue<B>> stepB, Function<B, javafx.beans.value.ObservableValue<C>> stepC, Function<C, javafx.beans.value.ObservableValue<D>> stepD) Creates a binding to get an observable valuea.b.c.d.- Type Parameters:
A- the type ofaB- the type ofbC- the type ofcD- the type ofd- Parameters:
root- observable valueastepB- the function that getsa.bstepC- the function that getsb.cstepD- the function that getsc.d- Returns:
- the binding
a.b.c.
-
viaBidirectional
public static <A,B> javafx.beans.property.Property<B> viaBidirectional(javafx.beans.value.ObservableValue<A> root, Function<A, javafx.beans.property.Property<B>> step) Creates a binding to get a propertya.b.- Type Parameters:
A- the type ofaB- the type ofb- Parameters:
root- observable valueastep- the function that getsa.b- Returns:
- the binding
a.b.
-
viaBidirectional
public static <A,B, javafx.beans.property.Property<C> viaBidirectionalC> (javafx.beans.value.ObservableValue<A> root, Function<A, javafx.beans.value.ObservableValue<B>> stepB, Function<B, javafx.beans.property.Property<C>> stepC) Creates a binding to get a propertya.b.c.- Type Parameters:
A- the type ofaB- the type ofbC- the type ofc- Parameters:
root- observable valueastepB- the function that getsa.bstepC- the function that getsb.c- Returns:
- the binding
a.b.c.
-
viaBidirectional
public static <A,B, javafx.beans.property.Property<D> viaBidirectionalC, D> (javafx.beans.value.ObservableValue<A> root, Function<A, javafx.beans.value.ObservableValue<B>> stepB, Function<B, javafx.beans.value.ObservableValue<C>> stepC, Function<C, javafx.beans.property.Property<D>> stepD) Creates a binding to get a propertya.b.c.d.- Type Parameters:
A- the type ofaB- the type ofbC- the type ofcD- the type ofd- Parameters:
root- observable valueastepB- the function that getsa.bstepC- the function that getsb.cstepD- the function that getsc.d- Returns:
- the binding
a.b.c.
-