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

前端 未结 2 1354
遥遥无期
遥遥无期 2020-11-29 13:01

I have a problem here. I create program to add data to the table and sort it when i press the button. when i press the sort button once, it isn\'t wrong. but when i press ag

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-29 13:27

    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

    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

提交回复
热议问题