Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JTable - ActionListener for select a row [closed]

I need the right AcionListener for my JTable.

At program start there is no row selected by default. If I now select any row in this JTable then the ActionListener shall start.

like image 927
user3057184 Avatar asked Dec 02 '13 11:12

user3057184


1 Answers

Try this. I use a ListSelectionListener and it works for me. I added a listener to the table Model

jTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
    @Override
    public void valueChanged(ListSelectionEvent event) {
        if (jTable.getSelectedRow() > -1) {
            // print first column value from selected row
            System.out.println(jTable.getValueAt(jTable.getSelectedRow(), 0).toString());
        }
    }
});
like image 121
Paul Samsotha Avatar answered Sep 18 '22 08:09

Paul Samsotha