Java – JTable – actionlistener for selecting rows
•
Java
My JTable needs the correct acionlister
When the program starts, no rows are selected by default If I select any row in this JTable now, the actionlistener will start
Solution
Try this I use listselectionlistener, which applies to 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()); } } });
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码