aspose file tools*
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 Soft Skills 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
Author

TableSorter and Selection gives problems

Grub de Bliek
Greenhorn

Joined: Sep 09, 2003
Posts: 19
Hello,

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: http://aspose.com/file-tools
 
subject: TableSorter and Selection gives problems