6

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??

KNB
  • 97
  • 3
  • 9
  • Can you provide more detail? You want `btnOrder` to be disabled when the value computed by `result` becomes true? Are `txtItem` and `txtQty` text fields, or something similar? – James_D Aug 09 '17 at 15:48

1 Answers1

10

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)));
James_D
  • 201,275
  • 16
  • 291
  • 322
  • And if I want to check the values.. lets say if the value of txtItem is less than the value of txtQty, then button must enable – KNB Aug 09 '17 at 16:36
  • @kasun Just include that condition in the evaluation function in the first version. (If you're converting the text to numeric values, then I don't think there's an equivalent of the second version that will work.) – James_D Aug 09 '17 at 16:37