假设我有两个属性,并且我想绑定第三个属性以等于它们之间的计算。
在此示例中,我有 aval1和 afactor属性。我希望该result属性与两者的“幂”绑定:result = Math.pow(factor, val1)
以下 MCVE 显示了我当前如何尝试这样做,但它没有正确绑定。
import javafx.beans.binding.Bindings;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleIntegerProperty;
public class Main {
private static DoubleProperty val1 = new SimpleDoubleProperty();
private static DoubleProperty factor = new SimpleDoubleProperty();
private static DoubleProperty result = new SimpleDoubleProperty();
public static void main(String[] args) {
// Set the value to be evaluated
val1.set(4.0);
factor.set(2.0);
// Create the binding to return the result of your calculation
result.bind(Bindings.createDoubleBinding(() ->
Math.pow(factor.get(), val1.get()))); …Run Code Online (Sandbox Code Playgroud)