views:

28

answers:

3

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ć
+1  A: 

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

dpb
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