Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

TableSorter and Selection gives problems

 
Grub de Bliek
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Don Kiddick
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you use the getViewToModel method?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic