开发者

Sorting Long integers with Java TableRowSorter

开发者 https://www.devze.com 2023-01-05 04:39 出处:网络
I\'m have a table that handles large numbers, and I want it to be sorted. The table has no problem displaying the numbers, but TableRowSorter seems to treat the numbers as Integers,开发者_如何转开发 t

I'm have a table that handles large numbers, and I want it to be sorted. The table has no problem displaying the numbers, but TableRowSorter seems to treat the numbers as Integers,开发者_如何转开发 thus sorting large values incorrectly when they exceed the maximum Integer value. How can I use TableRowSorter to sort Longs?


but TableRowSorter seems to treat the numbers as Integers, thus sorting large values incorrectly when they exceed the maximum Integer value

Thats because by default data added to a table is treated as a String. You need to override the getColumnClass() method of your TableModel to return the proper Class of the data in the column and the row sorter will use the appropriate Comparator for that type of data.


You could try to specify your own comparator that will provide details of how to compare the values.


Treat these long numbers as strings and table row sorter will sort them properly.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号