Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX: bind disable property of a button to ObservableList size

I have a TableView and I would like to bind the disable property of a Button with the size of the ObservableList model of the table. In particular, I would like to disable the button when the size of the ObservableList is grater than 2.

How can I achieve that?

To disable another button when no row is selected in table I used

editRoadButton.disableProperty().bind(roadsTable.getSelectionModel().selectedItemProperty().isNull());

Is there a similar way?

like image 438
Giorgio Avatar asked Jun 16 '14 14:06

Giorgio


1 Answers

There are factory methods for useful bindings in the Bindings class. In your case f.i.:

button.disableProperty().bind(Bindings.size(items).greaterThan(2));
like image 153
kleopatra Avatar answered Sep 19 '22 08:09

kleopatra