开发者

Sorting Long integers with Java TableRowSorter

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜