TableSorter.java

I read up on 'How to Use Tables'. I am using the TableSorter.java helper class from: http://java.sun.com/docs/books/tutorial/uiswing/components/table.html and have a small question regarding that. If I wanted to sort my JTable only from the second row onwards and leave the first row alone, how would I do that? The reason for me leaving out the first row is that I have provided the first row for the user to type in search parameters. I do not want the sorting function to mess with that row. I am using TableSorter.java as it is and ofcourse it is taking the empty cells of the first row into consideration and sorting those also. I do not want the TableSorter.java to consider the first row. I tried tweaking the TableSorter.java but to now avail. I was wondering if somebody used TableSorter.java before and had success in tweaking the code? Thanks in advance.

The way that I am using it right now..

TableSorter sorter = new TableSorter(tblOrders.getModel());

tblOrders.setModel(sorter);

sorter.setTableHeader(tblOrders.getTableHeader());

I went into TableSorter.java itself and tried to tweak this part of the code but it breaks..:(.

private Row[] getViewToModel() {

if (viewToModel == null) {

int tableModelRowCount = tableModel.getRowCount();

System.out.println("ROW COUNT : " + tableModelRowCount);

viewToModel = new Row[tableModelRowCount];

for (int row = 1; row < tableModelRowCount; row++) {

viewToModel[row] = new Row(row);

}

if (isSorting()) {

Arrays.sort(viewToModel);

}

}

System.out.println("viewToModel has : " + viewToModel.length);

return viewToModel;

}

I changed from int row = 0; to int row = 1;

cheers,

Misty.

[1786 byte] By [myswinga] at [2007-11-26 23:55:30]
# 1

Instead of tweaking with TableSorter.java code, use the same concept used by TableSorter.

Don't put the first row inside your original table model.

Wrap TableSorter inside your own TableModel, and return the first row for index 0, and the values inside TableSorter for the other rows.

Of course you will need to return row count + 1 of the TableSorter.

Rodney_McKaya at 2007-7-11 15:39:26 > top of Java-index,Desktop,Core GUI APIs...