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
gdkinney_2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.