JavaFX:绑定按钮禁用属性到ComboBox和DatePicker

whi*_*tes 5 binding combobox javafx datepicker javafx-8

我的fxml包含一个TextField,一个ComboBox,一个DatePicker和一个Button,只有在上面的对象不为空时才能启用它.

@FXML private TextField numText;
@FXML private ComboBox societeComboBox;
@FXML private DatePicker dateCreationPicker; 

@FXML private Button ajoutBtn; 
Run Code Online (Sandbox Code Playgroud)

我想出了如何将按钮的禁用属性绑定到TextField,但我无法弄清楚如何为ComboBox和DatePicker执行相同操作.

 ajoutBtn.disableProperty().bind(
        Bindings.isEmpty(numText.textProperty())  );
Run Code Online (Sandbox Code Playgroud)

Ulu*_*Biy 7

ComboBox和DatePicker都valueProperty可以用来检查它们的空虚.您可以OR他们disableProperty的按钮

ajoutBtn.disableProperty().bind(
        numText.textProperty().isEmpty()
        .or( societeComboBox.valueProperty().isNull() )
        .or( dateCreationPicker.valueProperty().isNull() ) );
Run Code Online (Sandbox Code Playgroud)