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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:27:21+00:00 2026-06-14T14:27:21+00:00

I want to recreate a table header looks using JLabel . The look and

  • 0

I want to recreate a table header looks using JLabel. The look and feel of the JLabel needs to be exactly like the JTableHeader would be, specified by the system.

This is what I have tried so far:

JLabel header = new JLabel("Title");
header.setOpaque(true);
header.setBackground(UIManager.getColor(new JTableHeader().getBackground()));
header.setBorder(UIManager.getBorder(new JTableHeader().getBorder()));

But, the UIManager returns null for the color and border.

Any ideas?

This is how I set the Look and Feel:

javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());
  • 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-14T14:27:22+00:00Added an answer on June 14, 2026 at 2:27 pm

    There are more issues involved then just getting the color and border of the table header. Each cell/column is rendered by a TableCellRenderer meaning that the values return by the UIManager may be ignored…

    For example, the following renders the JTableHeader and applies border/background to a JLabel based on values returned by the UIManager under the Window’s Look and Feel…

    enter image description here

    As you can see, there’s quite a difference between them

    How ever, if all you’re interested in is display a “group header” of some kind over the top of another component on a scroll pane, you could simply add a JTableHeader to the scroll panes column view directly…

    enter image description here

    public class TestHeader {
    
        public static void main(String[] args) {
            new TestHeader();
        }
    
        public TestHeader() {
            EventQueue.invokeLater(new Runnable() {
                @Override
                public void run() {
                    try {
                        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                    } catch (ClassNotFoundException ex) {
                    } catch (InstantiationException ex) {
                    } catch (IllegalAccessException ex) {
                    } catch (UnsupportedLookAndFeelException ex) {
                    }
    
                    TableColumnModel model = new DefaultTableColumnModel();
                    final TableColumn column = new TableColumn(0, 250);
                    column.setHeaderValue("Test");
                    model.addColumn(column);
    
                    JTableHeader header = new JTableHeader();
                    header.setColumnModel(model);
    
                    final JTextArea textArea = new JTextArea();
    
                    JScrollPane scrollPane = new JScrollPane(textArea);
                    scrollPane.setColumnHeaderView(header);
    
                    textArea.addComponentListener(new ComponentAdapter() {
                        @Override
                        public void componentResized(ComponentEvent e) {
                            column.setWidth(textArea.getWidth());
                        }
                    });
    
                    JFrame frame = new JFrame();
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.setLayout(new BorderLayout());
                    frame.add(scrollPane);
                    frame.pack();
                    frame.setLocationRelativeTo(null);
                    frame.setVisible(true);
                }
            });
        }
    }
    

    UPDATED

    enter image description here

    public class TestHeader {
    
        public static void main(String[] args) {
            new TestHeader();
        }
    
        public TestHeader() {
            EventQueue.invokeLater(new Runnable() {
                @Override
                public void run() {
                    try {
                        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                    } catch (ClassNotFoundException ex) {
                    } catch (InstantiationException ex) {
                    } catch (IllegalAccessException ex) {
                    } catch (UnsupportedLookAndFeelException ex) {
                    }
    
                    TableColumnModel model = new DefaultTableColumnModel();
                    final TableColumn column = new TableColumn(0, 250);
                    column.setHeaderValue("I don't see the problem");
                    model.addColumn(column);
    
                    final JTableHeader header = new JTableHeader();
                    header.setColumnModel(model);
    
                    DefaultTableModel tm = new DefaultTableModel(new Object[]{"A", "B", "C"}, 0);
                    tm.addRow(new Object[]{"1", "2", "3", "4"});
                    tm.addRow(new Object[]{"5", "6", "7", "8"});
                    tm.addRow(new Object[]{"9", "10", "11", "12"});
                    tm.addRow(new Object[]{"13", "14", "15", "16"});
                    final JTable table = new JTable(tm);
    
                    final JScrollPane scrollPane = new JScrollPane(table);
                    /**
                     * For some reason, the header isn't being applied as soon as the
                     * table is added to the scroll pane, so we need to jump our next
                     * request to the end of the of event queue so that it will
                     * occur some time in the future
                     */
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            scrollPane.setColumnHeaderView(header);
                        }
    
                    });
    
                    table.addComponentListener(new ComponentAdapter() {
                        @Override
                        public void componentResized(ComponentEvent e) {
                            column.setWidth(table.getWidth());
                        }
    
                    });
    
                    JFrame frame = new JFrame();
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.setLayout(new BorderLayout());
                    frame.add(scrollPane);
                    frame.pack();
                    frame.setLocationRelativeTo(null);
                    frame.setVisible(true);
                }
    
            });
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to recreate this using CSS only instead of a table code will
I want to recreate the following header: The problem is that the content is
want to know why String behaves like value type while using ==. String s1
I am attempting to recreate a table using block elements (in this case an
I am trying to recreate a table element using inline blocks of fixed width,
I am using sqlite3 for my iOS project. When login/logout i want to recreate
I simply want to drop the table 'whatever' if it exist and then recreate
I want to recreate the the update panel postback without using an update panel
I dropped a table manually in magento. Now I want my code to recreate
I'm trying to recreate a table with divs. I want to be able 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.