KNB
KNB

Reputation: 127

javafx - Bind button according to boolean value

Here, I want to disable and enable button according to the value of the boolean.

boolean result=(txtItem.getText().isEmpty() && txtQty.getText().isEmpty());

btnOrder.disableProperty().bind(xxxxx);

what should I enter there??

Upvotes: 6

Views: 6507

Answers (1)

James_D
James_D

Reputation: 209225

If I understand what you are asking (in particular, assuming txtItem and txtQty are some kind of TextInputControl), you can do

btnOrder.disableProperty().bind(Bindings.createBooleanBinding(
    () -> txtItem.getText().isEmpty() && txtQty.getText().isEmpty(),
    txtItem.textProperty(), txtQty.textProperty()));

or

btnOrder.disableProperty().bind(
    Bindings.length(txtItem.textProperty()).isEqualTo(0)
    .and(Bindings.length(txtQty.textProperty()).isEqualTo(0)));

Upvotes: 10

Related Questions