本文介绍了双向绑定到属性否定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给定
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.
希望有助于
这篇关于双向绑定到属性否定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!