Mateusz Dryzek Mateusz Dryzek - 3 months ago 15
Java Question

Bidirectional binding between ObjectProperty<Double> and DoubleProperty

Is there any built-in function to create a bidirectional binding between

DoubleProperty
and
ObjectProperty<Double>
?

For one direction binding it is pretty easy :

public void bindBidirectional(DoubleProperty doubleProperty, ObjectProperty<Double> doubleObjectProperty){
doubleProperty.bind(Bindings.createDoubleBinding(() -> doubleObjectProperty.get(), doubleObjectProperty));
}


but since
Bindings.createDoubleBinging
returns
Binding
, not
Property
I can't use it for bidirectional binding.

Answer

You can do

doubleObjectProperty().bindBidirectional(doubleProperty.asObject());