Detect doubleclick on row of TableView JavaFX

后端 未结 6 458
耶瑟儿~
耶瑟儿~ 2020-11-29 21:51

I need to detect double clicks on a row of a TableView.

How can I listen for double clicks on any part of the row and get all data of this row to print

6条回答
  •  清歌不尽
    2020-11-29 22:48

    If you are using SceneBuilder you can set your table's OnMouseClicked to handleRowSelect() method as shown below:

    MyType temp;
    Date lastClickTime;
    @FXML
    private void handleRowSelect() {
        MyType row = myTableView.getSelectionModel().getSelectedItem();
        if (row == null) return;
        if(row != temp){
            temp = row;
            lastClickTime = new Date();
        } else if(row == temp) {
            Date now = new Date();
            long diff = now.getTime() - lastClickTime.getTime();
            if (diff < 300){ //another click registered in 300 millis
                 System.out.println("Edit dialog");
            } else {
                lastClickTime = new Date();
            }
        }
    }
    

提交回复
热议问题