JTable - ActionListener to select a row

I need the correct AcionListener for my JTable .

When the program starts, the default line is not selected. If I select any row in this JTable , then the ActionListener will ActionListener .

+6
source share
1 answer

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

 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()); } } }); 
+19
source

Source: https://habr.com/ru/post/959162/


All Articles