javax.swing.JTable table = dBTable1.getTable();
javax.swing.ListSelectionModel rowSM = table.getSelectionModel();
int lastSelectedRow = 0;
rowSM.addListSelectionListener(new javax.swing.event.ListSelectionListener()
{
public void valueChanged(ListSelectionEvent e)
{
int currentSelectedRow = table.getSelectedRow();
if( currentSelectedRow == lastSelectedRow || currentSelectedRow == -1 )
return;
//this were you need to add the code to do the validation when user moves from one row to another
System.out.println("user moving from " + currentSelectedRow + " to " + lastSelectedRow);
//the row from which user is moving
int indexRow = lastSelectedRow;
//the column which we need to validate
int indexColonne = getColumnByDatabaseName(ClientFactureLigneTableDef.cCodeArticle).getModelIndex() - 1;
Object val = getValueAt(indexRow, indexColonne);
System.out.println( "row=" + indexRow + " checking column=" + indexColonne + " value=" + val);
if (val == null || val.toString().compareTo("")==0)
{
System.out.println( "value empty, so not allowing to go to next row");
//Important: consume the event, so that it doesn't move to next row
e.consume();
return;
}
else
{
System.out.println( "validation successfull");
}
//assign the last selected row to the current selected row, for future use
lastSelectedRow = currentSelectedRow;
}
});