tags:

views:

48

answers:

2

i want to select particular rows from the JTable which contains a particular string.. please help me for this..

A: 

Call JTable.getModel then just loop through using TableModel.getValueAt

Matthew Flaschen
A: 

Something like this will do the trick:

void selectMatchingRows(JTable table, String regex) 
{    
  for (int row = 0; row < table.getModel().getRowCount(); row++) 
  {
    for (int col = 0; col < table.getModel().getColumnCount(); col++) 
    {
      if (table.getModel().getValueAt(row, col).toString().matches(regex)) 
      {
        table.getSelectionModel().setSelectionInterval(row, row);
      }
    }
  }
}

Making sure the ListSelectionModel.selectionMode is MULTIPLE_INTERVAL_SELECTION.

Nick Holt