10

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.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
user3057184
  • 133
  • 1
  • 1
  • 8
  • 1
    Do you ***see*** an `addActionListener(..)` method in [The Fine Manual](http://docs.oracle.com/javase/7/docs/api/javax/swing/JTable.html)? What 'add listener' methods *do* you see? – Andrew Thompson Dec 02 '13 at 11:25

1 Answers1

26

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());
        }
    }
});
Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720