问题
Given
DoubleProperty A;
DoubleProperty minusA;
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()
?
回答1:
I tried but did´t find a way by using a bidirectional binding but maybe you could use an InvalidationListner on both?
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);
});
then you could easily call the setter method of both DoubleProperties and the other value will change to the negativ value.
Hope that helps
来源:https://stackoverflow.com/questions/34439109/bidirectionally-bind-to-property-negation