From: stormreaver
Written: 2009-09-08 12:39:39.363222
Subject: Detecting JTable Selection Change

To detect when the user selects a different row in a JTable, you must add a selection listener to the JTable's selection model. The selection model, as its name implies, handles processing the user's selection. You can organize the code however you want, but this is the bare minimum code needed to allow your program to detect when the user selects a different row:


protected ListSelectionModel m_modelSelection = table.getSelectionModel();

m_modelSelection.addListSelectionListener(new ListSelectionListener()
{
public void valueChanged(ListSelectionEvent e)
{
System.out.println("Table changed " + Math.random());
}
});


That's all there is to it. You can change the selection using any input device, and the selection listener will be activated.
You must register an account before you can reply.