how to bind inverse boolean, JavaFX
Using the EasyBind library one can easily create a new ObservableValue that from checkbox.selectedProperty()
that has the invert of its values.
paneWithControls.disableProperty().bind(EasyBind.map(checkbox.selectedProperty(), Boolean.FALSE::equals));
If you want only a one-way binding, you can use the not()
method defined in BooleanProperty
:
paneWithControls.disableProperty().bind(checkBox.selectedProperty().not());
This is probably what you want, unless you really have other mechanisms for changing the disableProperty()
that do not involve the checkBox
. In that case, you need to use two listeners:
checkBox.selectedProperty().addListener((obs, wasSelected, isNowSelected) ->
paneWithControls.setDisable(! isNowSelected));
paneWithControls.disableProperty().addListener((obs, wasDisabled, isNowDisabled) ->
checkBox.setSelected(! isNowDisabled));
checkbox.selectedProperty().bindBidirectional(paneWithControls.disableProperty().not());
should work