【问题标题】:Bidirectional binding between ObjectProperty<Double> and DoublePropertyObjectProperty<Double> 和 DoubleProperty 之间的双向绑定
【发布时间】:2026-01-07 19:50:01
【问题描述】:

是否有任何内置函数可以在DoublePropertyObjectProperty&lt;Double&gt; 之间创建双向绑定?

单向绑定非常简单:

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

但由于Bindings.createDoubleBinging 返回Binding,而不是Property,我不能将其用于双向绑定。

【问题讨论】:

    标签: java javafx binding javafx-8


    【解决方案1】:

    你可以的

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

    【讨论】:

    • 谢谢,正是我想要的:)