所以我认为你对于属性的工作原理有错误的想法。我做了一个例子更好地理解:
import javafx.beans.binding.Bindings;
import javafx.beans.binding.NumberBinding;
import javafx.beans.property.FloatProperty;
import javafx.beans.property.SimpleFloatProperty;
public class Test {
public static void main(String... args) {
FloatProperty dummyProp = new SimpleFloatProperty(0);
FloatProperty binderP = new SimpleFloatProperty(-1);
//Means boundP = dummyProp + binderP
NumberBinding boundP = Bindings.add(binderP, dummyProp);
System.out.format("%f + %f = %f%n", dummyProp.floatValue(), binderP.floatValue(), boundP.floatValue());
dummyProp.set(2);
System.out.format("%f + %f = %f%n", dummyProp.floatValue(), binderP.floatValue(), boundP.floatValue());
// dummyProp is equal to binderP but dummyProp is a read-only value
dummyProp.bind(binderP);
System.out.format("%f, %f%n", dummyProp.floatValue(), binderP.floatValue());
// throws an exception because dummyProp is bound to binderP
// dummyProp.set(5);
binderP.set(5f);
System.out.format("%f, %f%n", dummyProp.floatValue(), binderP.floatValue());
dummyProp.unbind();
// dummyProp == binderP always
dummyProp.bindBidirectional(binderP);
System.out.format("%f, %f%n", dummyProp.floatValue(), binderP.floatValue());
dummyProp.set(3f);
System.out.format("%f, %f%n", dummyProp.floatValue(), binderP.floatValue());
binderP.set(10f);
System.out.format("%f, %f%n", dummyProp.floatValue(), binderP.floatValue());
// boundP always consists of the sum
System.out.format("%f%n", boundP.floatValue());
}
}
我认为你需要看看教程再次看到绑定是如何工作的:https://docs.oracle.com/javase/8/javafx/properties-binding -tutorial/binding.htm#sthref8 – Flown
感谢Flown--在以下回答中张贴的回复 – Tel
你知道什么*按价值*打电话吗? – Holger