双向绑定到属性否定
问题描述:
给定
DoubleProperty A;
DoubleProperty minusA;
有没有办法双向绑定他们的否定对方,所以A.get()= = -minusA.get(),两者都可以是 set()
?
is there a way to bind their negations bidirectionally to each other, so that A.get() == -minusA.get() at all times, and both can be set()
?
答
我尝试过,但没有找到一种使用双向绑定的方法,但也可能在两者上都可以使用InvalidationListner?
I tried but did´t find a way by using a bidirectional binding but maybe you could use an InvalidationListner on both?
p>
Something like
A.addListener((Observable observable) -> {
System.out.println("A is invalid");
minusA.set(A.get() *-1);
});
minusA.addListener((Observable observable) -> {
System.out.println("minusA is invalid");
A.set(minusA.get() * -1);
});
那么你可以很容易地调用这两个DoubleProperties的setter方法,另一个值将改变为negativ值
then you could easily call the setter method of both DoubleProperties and the other value will change to the negativ value.
希望有助于