This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes TableSorter and Selection gives problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "TableSorter and Selection gives problems" Watch "TableSorter and Selection gives problems" New topic

TableSorter and Selection gives problems

Grub de Bliek

Joined: Sep 09, 2003
Posts: 19

I'm trying to use a JTable in combination with the Sun TableSorter (v2.0 02/27/04). All works fine, but the user selection on the JTable disappears, when rows are added dynamically.

TableSorter provides a the method public int modelIndex(int viewIndex), so it's always possible to modify the correct row in the tablemodel when you only have an index of the view.
However, what I need is to retreive the index of the view, while I only have the index of the tableModel.

It works like this:
1. Before I add a row to the tableModel, I can get the selected rows from the JTable, and retrieve the indexes of the tableModel with the method modelIndex.
2. Then I add the row. Practically it is inserted in the view, because my Table is sorted. The row is added to the end of the TableModel, but inserted somewhere at an unknown place in the JTable.
3. I still have the tableModel indexes of the selected rows, and I just need to know their view indexes. But here I'm stuck. There's no way I can convert a modelIndex to a viewIndex.

By the way I'm using MULTIPLE_INTERVAL selections.

Here's the Sun TableSorter I'm using:

[ June 23, 2005: Message edited by: Grub de Bliek ]

When the compiler isn't happy, nobody is happy...
Don Kiddick
Ranch Hand

Joined: Dec 12, 2002
Posts: 580
can you use the getViewToModel method?
I agree. Here's the link:
subject: TableSorter and Selection gives problems
It's not a secret anymore!