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 9246831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:35:06+00:00 2026-06-18T09:35:06+00:00

I have an JTable which is using RowSorter(Java 1.6) and I am using the

  • 0

I have an JTable which is using RowSorter(Java 1.6) and I am using the look and feel which was implemented using Java 1.4, when RowSorter was not added in Java. Now my problem is: when I click on the table header, table gets sorted but the RosSorter icon does not appear on the Table header. I need that icon somehow and I can not upgrade the existing look and feel. Any help ?

  • 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-06-18T09:35:07+00:00Added an answer on June 18, 2026 at 9:35 am

    The basic approach is to wrap the renderer that is supplied by the LAF, let it configure the rendering component and additionally make it paint a sort icon as appropriate. Something like:

    final TableCellRenderer r = table.getTableHeader().getDefaultRenderer();
    TableCellRenderer wrapper = new TableCellRenderer() {
    
        @Override
        public Component getTableCellRendererComponent(JTable table,
                Object value, boolean isSelected, boolean hasFocus,
                int row, int column) {
            Component comp = r.getTableCellRendererComponent(table, value, isSelected, 
                hasFocus, row, column);
            if (comp instanceof JLabel) {
                JLabel label = (JLabel) comp;
                label.setIcon(getSortIcon(table, column));
            }
            return comp;
        }
    
        /**
         * Implements the logic to choose the appropriate icon.
         */
        private Icon getSortIcon(JTable table, int column) {
            SortOrder sortOrder = getColumnSortOrder(table, column);
            if (SortOrder.UNSORTED == sortOrder) {
                return null;
            }
            return SortOrder.ASCENDING == sortOrder ? ascendingIcon : descendingIcon;
        }
    
        private SortOrder getColumnSortOrder(JTable table, int column) {
            if (table == null || table.getRowSorter() == null) {
                return SortOrder.UNSORTED;
            }
            List<? extends SortKey> keys = table.getRowSorter().getSortKeys();
            if (keys.size() > 0) {
                SortKey key = keys.get(0);
                if (key.getColumn() == table.convertColumnIndexToModel(column)) {
                    return key.getSortOrder();
                }
            }
            return SortOrder.UNSORTED;
        }
    
    };
    table.getTableHeader().setDefaultRenderer(wrapper);
    

    That’s the easiest case, working if the rendering component is-a JLabel and doesn’t use its icon property somehow else.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with JTable / JScrollPane . My data table is not
I have a JTable which is loaded from a data-structure using table model.The data-structure
I am using Derby database with Java and Eclipse. I have a table which
I have a JTable which I want to have left-click and right-click JPopupMenu on
I have a JTable using a custom DefaultTableModel which has some Booleans in the
I have a JTable which is created using a TableModel JTable t = new
I am using a jtable which have 8 rows by default. When I add
I have the following JTable which uses a table model: http://s17.postimage.org/7zfh3l4lr/Screen_Shot_2012_03_10_at_15_11_31.png Instead of using,
I have a JTable which has 1st row blank. Now when I sort the
I am working on a Java GUI, in which i have a JTable 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.