I have a button on my interface that is disabled by default. I want it to become enabled when the user selects a row in my TableView and becomes disabled again when the user clicks elsewhere. What is the simplest way to do this?
Seems like a perfect place to use JavaFX Bindings:
TableView<String> tableView = new TableView<>(tableData);
TableColumn<String, String> column1 = new TableColumn<>();
Button button = new Button("Button");
button.disableProperty().bind(Bindings.isEmpty(tableView.getSelectionModel().getSelectedItems()));
This example disables the Button
when the user has selected nothing or cleared his selection and becomes enabled as soon as at least one row is being selected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With