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
@Das: maybe this version is better since you do not need to override the getRowCount(), which may be used and maybe causing problems by other functions
public class TableRowSorterTotal extends TableRowSorter
{
TableRowSorterTotal(MyTableModel model)
{
super(model);
}
public int convertRowIndexToModel(int index)
{
int maxRow = super.getViewRowCount();
int currModel = super.convertRowIndexToModel(index);
int maxModel = super.convertRowIndexToModel(maxRow-1);
if(currModel == maxModel)
return maxRow - 1;
if(currModel > maxModel)
return currModel- 1;
return currModel;
}
public int convertRowIndexToView(int index)
{
int maxRow = super.getModelRowCount();
int currView= super.convertRowIndexToView(index);
int maxView = super.convertRowIndexToView(maxRow-1);
if(currView == maxView)
return maxRow - 1;
if(currView > maxView)
return currView- 1;
return currView;
}
}