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 are similar questions on this topic, but I still cannot find
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 there seems to be many questions on this forum for searching multiple
I realize that there have already been several threads on this type of question,
I realize that there was a similar question asked here , but this is
I realize there are several other questions pertaining to this - but either they
I realize this is syntactically bad but I figure it somewhat explains what I'm
I realize that a SO user has formerly asked this question but it was
I realize there is a very interesting technique, to get Context in Android in

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.