JTable - Selected Row click event

前端 未结 5 950
名媛妹妹
名媛妹妹 2021-02-02 09:36

I have a Jtable that is populated with a linkedlist through an AbstractTableModel.

What I want to do is when I click (left-mouse click) on a row in the JTable, the linke

5条回答
  •  时光取名叫无心
    2021-02-02 10:09

    Here's how I did it:

    table.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
            public void valueChanged(ListSelectionEvent event) {
                // do some actions here, for example
                // print first column value from selected row
                System.out.println(table.getValueAt(table.getSelectedRow(), 0).toString());
            }
        });
    

    This code reacts on mouse click and item selection from keyboard.

提交回复
热议问题