DefaultTableModel tableModel = (DefaultTableModel)tableComp.getTableModel();
int rowCount = tableModel.getRowCount();
List<Object[]> rows = new ArrayList<Object[]>(rowCount);
for(int row = 0; row < rowCount; row++)
{
NameValue name = (NameValue)tableModel.getValueAt(row,0);
NameValue desc = (NameValue)tableModel.getValueAt(row,1);
rows.add(new Object[] { name, desc });
}
Collections.sort(rows, new Comparator<Object[]>()
{
public int compare(Object[] o1, Object[] o2)
{
NameValue name1 = (NameValue)o1[0];
NameValue name2 = (NameValue)o2[0];
int order = name1.getName().compareTo(name2.getName());
if (!ascending) order = -order;
return order;
}
}
);