我的JTable需要正确的AcionListener.
在程序启动时,默认情况下不会选择任何行.如果我现在选择此JTable中的任何行,则ActionListener将启动.
解决方法
试试这个.我使用ListSelectionListener,它适用于我.我在表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());
- }
- }
- });