How to disable Button when TextField is empty?

后端 未结 3 1958
暖寄归人
暖寄归人 2020-11-27 06:03

In the following code I have a TextField and a Button. I need to disable the Button when ever the TextField is empty, so that I can avoid entering empty values to the databa

3条回答
  •  醉梦人生
    2020-11-27 06:48

    Similar to Uluk's answer, but using the Bindings fluent API:

    btn.disableProperty().bind(
        Bindings.isEmpty(textField1.textProperty())
        .and(Bindings.isEmpty(textField2.textProperty()))
        .and(Bindings.isEmpty(textField3.textProperty()))
    );
    

    Also note that, this new overloaded method of Bindings is added in JavaFX-8 and not avaliable in JavaFX-2.

提交回复
热议问题