ListSelectionModel rowSM = table.getSelectionModel();
rowSM.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
ListSelectionModel lsm = (ListSelectionModel) e.getSource();
if (lsm.isSelectionEmpty()) {
System.out.println("没有选中任何行.");
} else {
int selectedRow = lsm.getMinSelectionIndex();
System.out.println("第" + selectedRow+ "行被选中");
}
}
});我想的是鼠标单击JTable返回选中的行号。。这样写合理吗?