JTable sorting prob
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   prashanth_narayan
Posted On:   Sunday, August 18, 2002 10:22 PM

I got one problem in JTable sorting well I created a TableModel called sorttabletablemodel.java wut I am doin inside is sorting the indexes, this is the way I am getting indexes int[] indexes = model.getIndexes(); and i am sorting this index values, well its working fine , but wut happens is whn I sort the table and delete one row for eg before sorting dell csco msft ibm after sorting csco dell ibm msft and try to delete dell after sorting the csco got deleted it means the tables rows are not sorted actually , how to avoid this??? thx in advance    More>>

I got one problem in JTable sorting well I created a TableModel called sorttabletablemodel.java wut I am doin inside is sorting the indexes, this is the way I am getting
indexes
int[] indexes = model.getIndexes();

and i am sorting this index values, well its working fine ,
but wut happens is whn I sort the table and delete one row for eg
before sorting

			
dell
csco
msft
ibm

after sorting

csco
dell
ibm
msft
and try to delete dell after sorting the csco got deleted it means the tables rows are not sorted actually , how to avoid this???
thx in advance
   <<Less

delete was performed on wrong row

Posted By:   Amar_Mattey  
Posted On:   Monday, August 19, 2002 08:22 AM

To me it looks like when sorting is done the table rows are
falsed in the SortedTableModel and displayed.



2 things can be done here


1) If row number 2 needs to be deleted we need to say

tableModel.delete(index[2]) where index is the displced row
index.



2) Theoritically all the indexing should be hidden in the
table model itself so when we call delete we need to
use the index array which has the original row indexs to delete the rows.





Lets take your example
row originalIndex

dell 0
csco 1
msft 2
ibm 3

after sorting

row originalIndex displaying Index

csco 1 0
dell 0 1
ibm 3 2
msft 2 3

So when we call delete on dell we say deletItemAt(1) assuming displaying index is 1 but infact csco is the original item at index 1.


Hope this was helpfull.


Thanks.
About | Sitemap | Contact