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

  • Home
  • SEARCH
  • 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 6235515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:40:51+00:00 2026-05-24T10:40:51+00:00

I would like to sort JTable rows based on one hidden column. Say I

  • 0

I would like to sort JTable rows based on one hidden column.

Say I have a JTable like this

column1   column2
val1       val2

Now I have a one more column3 which is hidden and I dont want to show. When user clicks on Column2 it should sort rows based on Column3 (hidden column) not based Column2.

How to achieve this in JTable?

  • 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-24T10:40:51+00:00Added an answer on May 24, 2026 at 10:40 am

    you can add by default TableRowSorter to JTable but there is RowSorter, nothing better and clear around as Darryl’s Multisort Table Header Cell Renderer

    note definitions for RowSorter is valid only for concrete TableColumn

    siple example (with use-less balast again)

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.*;
    
    public class HeaderDoubleclickTest {
    
        private String[] columnNames = {"String", "Integer", "Boolean"};
        private Object[][] data = {
            {"aaa", 12, true}, {"bbb", 5, false},
            {"CCC", 92, true}, {"DDD", 0, false}
        };
        private TableModel model = new DefaultTableModel(data, columnNames) {
    
            private static final long serialVersionUID = 1L;
    
            @Override
            public Class<?> getColumnClass(int column) {
                return getValueAt(0, column).getClass();
            }
        };
        private JTable table = new JTable(model);
        private JTableHeader header;
    
        static class TestTableRowSorter extends TableRowSorter<TableModel> {
    
            TestTableRowSorter(TableModel m) {
                super(m);
            }
    
            @Override
            public void toggleSortOrder(int column) {
            }
    
            public void wrapToggleSortOrder(int column) {
                super.toggleSortOrder(column);
            }
        }
        private Timer timer = new Timer(400, new ActionListener() {
    
            @Override
            public void actionPerformed(ActionEvent e) {
                System.out.println("single");
                JTable table = header.getTable();
                RowSorter sorter;
                if (pt != null && table != null && (sorter = table.getRowSorter()) != null) {
                    int columnIndex = header.columnAtPoint(pt);
                    if (columnIndex != -1) {
                        columnIndex = table.convertColumnIndexToModel(columnIndex);
                        ((TestTableRowSorter) sorter).wrapToggleSortOrder(columnIndex);
                    }
                }
            }
        });
        private Point pt;
    
        public JComponent makeUI() {
            timer.setRepeats(false);
            table.setRowSorter(new TestTableRowSorter(model));
            header = table.getTableHeader();
            header.addMouseListener(new MouseAdapter() {
    
                @Override
                public void mouseClicked(final MouseEvent e) {
                    if (timer.isRunning() && !e.isConsumed() && e.getClickCount() > 1) {
                        System.out.println("double");
                        pt = null;
                        timer.stop();
                    } else {
                        pt = e.getPoint();
                        timer.restart();
                    }
                }
            });
            JPanel p = new JPanel(new BorderLayout());
            p.add(new JScrollPane(table));
            return p;
        }
    
        public static void main(String[] args) {
            EventQueue.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    createAndShowGUI();
                }
            });
        }
    
        public static void createAndShowGUI() {
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            f.getContentPane().add(new HeaderDoubleclickTest().makeUI());
            f.setSize(320, 240);
            f.setLocationRelativeTo(null);
            f.setVisible(true);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of files I would like to sort based on the
I have a many to many and would like to sort this so that
I would like to sort a matrix according to a particular column. There is
I have a result from an SQL query that I would like to sort
I would like to sort some objects that have a Name property. These objects
I have a find command that I would like to sort such that entries
I would like to ask something about query using mysql I have this table
Greetings, inside one of the column I have values like the following: 9-7 9-18
I have a multidimensional array which I would like to sort by two factors:
This is the data that I would like to sort. AAAAAAAA 0.0.0.0 hs01.stuff.net BBBBBBBB

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.