Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX : Binding button disable property to ComboBox and DatePicker

My fxml contains a TextField, a ComboBox, a DatePicker and a Button that should only be enabled when the objects above are not empty.

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

@FXML private Button ajoutBtn; 

i figured out how to bind the disable property of the button to the TextField but i can't figure out how to do the same for the ComboBox and the DatePicker.

 ajoutBtn.disableProperty().bind(
        Bindings.isEmpty(numText.textProperty())  );
like image 586
whites Avatar asked Aug 12 '15 09:08

whites


1 Answers

Both the ComboBox and the DatePicker have valueProperty that can be used for checking their emptiness. You can OR them to disableProperty of the button

ajoutBtn.disableProperty().bind(
        numText.textProperty().isEmpty()
        .or( societeComboBox.valueProperty().isNull() )
        .or( dateCreationPicker.valueProperty().isNull() ) );
like image 118
Uluk Biy Avatar answered Oct 04 '22 13:10

Uluk Biy