JavaFX8: How to create listener for selection of row in Tableview?

The selectedItem in the selection model is an observable property, so you should be able to achieve this with:

tableview1.getSelectionModel().selectedItemProperty().addListener((obs, oldSelection, newSelection) -> {
    if (newSelection != null) {
        tableview2.getSelectionModel().clearSelection();
    }
});

tableview2.getSelectionModel().selectedItemProperty().addListener((obs, oldSelection, newSelection) -> {
    if (newSelection != null) {
        tableview1.getSelectionModel().clearSelection();
    }
});

Leave a Comment