[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1021
  • Last Modified:

Need to sort a JTable column correctly in Java 1.6. So that "2" comes before "16" when I sort the column in ascending order.

Need to be able to sort a JTable column correctly in Java 1.6.  For example so that "2" comes before "16" when I sort the column in ascending order.

Thanks
0
gdkinney_2
Asked:
gdkinney_2
  • 3
  • 2
2 Solutions
 
contactkarthiCommented:
have a look at this url

http://exampledepot.com/egs/javax.swing.table/SortCol.html

there there will be a implementation class for comparator called as ColumnSorter modify that class so that it compares the values as integers and not string. that way you will get 2 before 16
0
 
gdkinney_2Author Commented:
Actually I need to sort my rows in a JTable when a user clicks on the heading for a column in my JTable.  So all rows will be sorted (ascending or descending) based on the data in the clicked column.
0
 
contactkarthiCommented:
can you post the code soit will be easy for me to point out where to change
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
ksivananthCommented:
>>For example so that "2" comes before "16" when I sort the column in ascending order

if the values are integer/numeric pass them as approprite object type rather String. for e.g., if it is integer, new Integer( 2 ) instead of "2"!
0
 
ksivananthCommented:
also make sure the column class returned appropriately by the model. for e.g., for int, return Integer.class
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now