且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何选择JTable中最后插入的行?

更新时间:2023-12-03 14:37:10

问题很可能在你的 TableModel ,因为您发布的代码很好。您提到使用 HashMap 来存储 TableModel 的数据。 HashMap 的问题在于它没有任何排序。向其添加元素可能会改变您在地图中获取元素的顺序。

The problem is most likely in your TableModel, since the code you posted is just fine. You mention you use a HashMap for storing the data of your TableModel. Problem with a HashMap is that it hasn't any ordering. Adding an element to it might alter the order in which you get the elements in the map.

***使用符合排序的数据结构。

Better to use a data structure which respects the ordering.