Reputation: 372
First, naive attempt:
booleanProperty1.bindBidirectional(booleanProperty2.not()); // type mismatch
This doesn't work. I either have to change it to unidirectional bind (so it will accept BooleanBinding
as an argument) or remove .not()
.
What would be the best way to actually achieve my goal here?
Upvotes: 2
Views: 324
Reputation: 9989
The most easiest way is to include listeners to both the properties and inverse the value to set on other property.
booleanProperty1.addListener((obs,old,val)->booleanProperty2.set(!val));
booleanProperty2.addListener((obs,old,val)->booleanProperty1.set(!val));
Upvotes: 3
Reputation: 363
Add a listener to booleanProperty2.
Upon its value changing (triggering the listener), set booleanProperty to the opposite of booleanProperty2.
Upvotes: 0