I have a JTable where the last row is the total row that aggregates all other rows. When the user clicks a column header on the table, rows are sorted by that c
The following solution worked for me....
In your table model update the getRowCount() member to return 1 row less than required.
Then modify the index and row counts reported by your sorter as follows...
TableRowSorter sorter =
new DefaultTableRowSorter(this.getModel())
{
public int convertRowIndexToModel(int index)
{
int maxRow = super.getViewRowCount();
if (index >= maxRow)
return index;
return super.convertRowIndexToModel(index);
}
public int convertRowIndexToView(int index)
{
int maxRow = super.getModelRowCount();
if (index > maxRow)
return index;
return super.convertRowIndexToView(index);
}
public int getViewRowCount()
{
return super.getViewRowCount() + 1;
}
};
myTable.setRowSorter(sorter);