Lukasz schrieb:
> Hi,
>
> I'm using TableSorter from page:
...
> I want to make the sorter work that way, that the first column will
> always stay as it is - unsorted, even if one of the other columns is
> sorted.
Have a look at how TableSorter works. It maps "view indices" to "model
indices" and vice versa. Therefore sorting the table means just to
update these indices. It is important to recognize this because it means
that the underlying model won't be changed.
The next thing to think about is how JTable gets the values to present
and how JTable applies changed values. This is done via getValueAt and
setValueAt.
Now, have a look at these two methods, you'll find the expression
modelIndex(row)
there. This method takes a view index and returns a model index.
So, all you need to do is to change this mapping in these two methods, e. g.
public Object getValueAt( int row, int col ) {
int modelRow = ( col > 0 ? modelIndex(row) : row );
return tableModel.getValueAt( modelRow, col );
}
Haven't tried it but seems to be OK while looking at TableSorter.java.
Bye
Michael
Lukasz - 24 Aug 2006 09:53 GMT
> So, all you need to do is to change this mapping in these two methods, e. g.
>
[quoted text clipped - 4 lines]
>
> Haven't tried it but seems to be OK while looking at TableSorter.java.
Thanks Michael, that works. Now these two methods look like this:
int modelRow = 0;
public Object getValueAt(int row, int column) {
//return tableModel.getValueAt(modelIndex(row), column);
modelRow = ( column > 0 ? modelIndex(row) : row );
return tableModel.getValueAt( modelRow, column );
}
public void setValueAt(Object aValue, int row, int column) {
tableModel.setValueAt(aValue, modelRow, column);
}
Michael Rauscher - 24 Aug 2006 11:57 GMT
Lukasz schrieb:
> Thanks Michael, that works. Now these two methods look like this:
>
[quoted text clipped - 7 lines]
>
> public void setValueAt(Object aValue, int row, int column) {
modelRow = ( column > 0 ? modelIndex(row) : row );
> tableModel.setValueAt(aValue, modelRow, column);
> }
Otherwise you'll run into trouble.
Bye
Michael