No I understood. I apologize for for being underappreciative of your
response. I'm just a little frustrated because it should be a
moderately simple thing to do. But it seems in this case Sun is
perfectly happy providing you with wood, knife and compass and saying,
make your own damn wheel.
> But it seems in this case Sun is
>perfectly happy providing you with wood, knife and compass and saying,
>make your own damn wheel.
Bingo! that is exactly what JTable is. Like the plans you send away
for to build a boat in the back of a magazine, or the "Bonzai kit"
that turns out to be a package of tree seeds. It is just a plan with
very little in the way of Sun's code.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
jozeph78 - 10 Nov 2005 17:02 GMT
Well for those of you who posted this question only receieve the "do it
yourself" answer, here is the code changes I made to the private
MouseHandler class. It gets the table from via
((TableHeader)MouseEvent.getSource()).getTable() to get the selcted
row's model index (note not selected rows), performs the sort, then
reselects the rows based on the model Index. Works well for me without
any changes to the Table using the sorter.
If anyone has any suggestions on how to tighten this up, please advise.
private class MouseHandler extends MouseAdapter {
public void mouseClicked(MouseEvent e) {
int viewColumn;
int column;
int [] modelIndiciesOfSelectedRows;
JTable table;
JTableHeader h;
TableColumnModel columnModel;
h = (JTableHeader) e.getSource();
table = h.getTable();
// JH get selected rows to reset later before canceling and/or
setting sorting status
modelIndiciesOfSelectedRows = getModelIndiciesOfSelectedRows(table);
columnModel = h.getColumnModel();
viewColumn = columnModel.getColumnIndexAtX(e.getX());
column = columnModel.getColumn(viewColumn).getModelIndex();
if (column != -1) {
int status = getSortingStatus(column);
if (!e.isControlDown()) {
cancelSorting();
}
status = (status <= 0) ? ASCENDING : DESCENDING;
setSortingStatus(column, status);
}
reselectPreviouslySelectedRows(table,modelIndiciesOfSelectedRows);
}
private int [] getModelIndiciesOfSelectedRows(JTable table){
int [] indicies = table.getSelectedRows();
int [] modelIndicies = new int[indicies.length];
for (int i = 0; i < indicies.length;i++){
modelIndicies[i] = modelIndex(indicies[i]);
}
return modelIndicies;
}
private void reselectPreviouslySelectedRows(JTable table, int []
selectedModelIndicies){
if (selectedModelIndicies.length != 0){
int selectedRow;
for(int i = 0; i < selectedModelIndicies.length;i++){
selectedRow = getModelToView()[selectedModelIndicies[i]];
table.addRowSelectionInterval(selectedRow,selectedRow);
}
Rectangle rect = table.getCellRect(table.getSelectedRow(),0,true);
table.scrollRectToVisible(rect);
}
}
}