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?
A:
Treat these long numbers as strings and table row sorter will sort them properly.
Boris Pavlović
2010-07-01 12:45:36
+1
A:
You could try to specify your own comparator that will provide details of how to compare the values.
dpb
2010-07-01 12:50:11
A:
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.
camickr
2010-07-01 14:55:03