Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 691
KNB Avatar asked Aug 09 '17 15:08

KNB


1 Answers

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)));
like image 53
James_D Avatar answered Nov 15 '22 11:11

James_D