[code lang=“java“]jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
ListSelectionModel rowSM = jTable.getSelectionModel();
rowSM.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting()) return; // ignore extra messages
ListSelectionModel lsm = (ListSelectionModel) e.getSource();
if (lsm.isSelectionEmpty()) {
// no rows are selected
} else {
int selectedRow = lsm.getMinSelectionIndex();
}
}
});[/code]