Home arrow static arrow Java Programming [Archive] - TableSorter and related issues
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - TableSorter and related issues
This topic has 5 replies on 1 page.

Posts:668
Registered: 9/2/03
TableSorter and related issues  
Aug 4, 2004 3:14 AM



 
Hi guys,

On some memorizer application I'm working on, notes are displayed via a JTable. These notes are added to the table's model through a method, addNote(Noteable note). This method extracts some information out of these Noteable objects and adds them as a row of 4 columns to the table. All of the notes are kept in a singleton observable NoteList object.

This works all fine and dandy, except when I want to use Sun's TableSorter (the newest version, 27 february or something). The point is, I am checking which note is selected out of the table by (very nasty) getting the selected row, and getting that index from a NoteList (singleton, observable). This fact means that selecting a rowindex of the table of 5, results in getting the note at index 5 from the NoteList, whether the table is sorted or not.

I think two reasonable solutions can be applied here but I am wondering which is the best and most practical:

1. Subclass the TableSorter to provide my own methods of adding, setting and getting the Notes at a specific index (although I am not sure this solutions will work, or work well).

2. Implement sorting methods in the NoteList singleton observable class. I think this means implementing about 4 methods of sorting (since the table shows 4 columns: Priority, Subject, Expiry date and Completed true/false).

Any ideas on this matter?
 

Posts:4,496
Registered: 19/06/02
Re: TableSorter and related issues  
Aug 4, 2004 3:23 AM (reply 1 of 5)



 
So you don't have all the data you need in the table? I mean you know the row that gets selected so you should just be able to pull all the relevant data from the 4 columns of that row. If the table doesn't have all the data you need, you can key your NoteList by a value held in a fifth hidden column. Now you can get the value from this fifth column of the selected row and retrieve the relevant not from the NoteList. This value can just be an integer that you increment for each new note. Trying to keep the table and the NoteList in synch will be a nightmare ....
 

Posts:668
Registered: 9/2/03
Re: TableSorter and related issues  
Aug 4, 2004 7:08 AM (reply 2 of 5)



 
I see, so you are suggesting something like a 'primary key' used in SQL? I must say this has crossed my mind before, but it didn't last that long in my head :P

I'll try it out, thanks for that suggestion.
 

Posts:1,577
Registered: 00-02-25
Re: TableSorter and related issues  
Aug 4, 2004 8:00 AM (reply 3 of 5)



 
Check out TableSorter.modelIndex() ... you pass it the table's row number, and it returns the row number of the model that you wrapped with TableSorter
 

Posts:668
Registered: 9/2/03
Re: TableSorter and related issues  
Aug 4, 2004 9:00 AM (reply 4 of 5)



 
Thanks! That one solved one problem I was facing: custom cell renderers (my IconCellRenderer to be exact).
 

Posts:668
Registered: 9/2/03
Re: TableSorter and related issues  
Aug 4, 2004 9:06 AM (reply 5 of 5)



 
Actually, that solved the whole issue!! Even though YoGee's solution did fit well too, yours quite solved it with all the ease I could imagine. Rest of the dukes are yours.
 
This topic has 5 replies on 1 page.