Sorting Table is wrong when the sort button be pressed more than once?

No where do you actually tell the TableModel that it’s contents have changed…

Now, the thing that weirds me out, is you are keeping a Vector of the rows outside of the model…

mS.merge_sort(0, rows.size()-1, n);
temp.setSize(rows.size());
for(int i=0;i<index;i++){
    temp.set(i, rows.get(n[i].ind()));
}
for(int i=0;i<index;i++){
    rows.set(i, temp.get(i)); // This is doing nothing...
}

Once the data has been handed to the table model, you should not be interacting with it, unless you are willing to notify the table model of the changes.

Personally, I would simply use the inbuilt sorting capabilities of the JTable

ps- I would also, strongly, encourage you to learn how to use layout managers, they will save your sanity in the long run

Leave a Comment