Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6011097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:12:38+00:00 2026-05-23T02:12:38+00:00

How do I realize sorting of columns containing only numbers in a JTable? There

  • 0

How do I realize sorting of columns containing only numbers in a JTable? There is the class TableRowSorter. Using this, however, leads to the following: for every number the string representation is taken by invoking toString and then this is compared instead. What I receive is for instance this:

100, 13, 2, 22, 9
instead 2, 9, 13, 22, 100

TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(table);
table.setRowSorter(sorter);

To avoid this, there is the following method:

sorter.setComparator(column,comparator);

Since my numbers are only Integer, Long and Double, I don’t see why I should define a humble Comparator of standard java.lang classes. Is there an easier way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T02:12:39+00:00Added an answer on May 23, 2026 at 2:12 am

    You should define Number for the column’s class.

    See TableModel

    public Class<?> getColumnClass(int columnIndex);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I realize there is a somewhat related thread on this here: Loading assemblies and
I realize there are several topics about this issue, but none provides a working
I realize there are several solutions to this problem. I am looking for advice
I realize that there was a similar question asked here , but this is
I realize that this question spans many technologies, but I am only looking for
I realize that there are many questions similar to this one, but having looked
I realize that since UNIX sockets are platform-specific, there has to be some non-Java
I realize this would violate convention, but I'm curious to know if you can
I realize that this would be COMPLETELY bad practice in normal situations, but this
I realize that the query this question is looking for won't be enough to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.