JTable - ActionListener for select a row
actionlistener, awt, java, jtable, swing
Solution
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());
}
}
});
Problem
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.