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

前端 未结 5 1371
广开言路
广开言路 2020-12-24 05:56

I currently have two tableviews in one screen, which results in both TableViews have rows which the user can select.

Now I want only one row to be selected at the sa

5条回答
  •  北海茫月
    2020-12-24 06:33

    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();
        }
    });
    

提交回复
热议问题