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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:40:32+00:00 2026-05-21T18:40:32+00:00

The JTableHaeder has no ‘pressed’ highlighting by default. (Nimbus) NimbusDefaults says it has a

  • 0

The JTableHaeder has no ‘pressed’ highlighting by default. (Nimbus)

NimbusDefaults says it has a default [Pressed] background painter.

What should I do, to see this when i click on the TableHeader?

NimbusDefaultPainter


UPDATE 1

The NimbusStyle.getExtendedState returns the PRESSED on mouseDown correctly. But the NimbusStyle.getBackgroundPainter(SynthContext) returns null cause there is an null in the NimbusStyle.Values cache for the CacheKey “backgroundPainter$$instance” with this state.

What is wrong there?


UPDATE 2

My example shows a JTableHeader and a JScrollBar with an ‘Pressed Behavior’.

For the JScrollBar my putClientProperty( "Nimbus.State" ) works with a repaint problem.

public class Header extends JPanel{

    public Header() {
        super(new BorderLayout());
        JTableHeader header = new JTable(5, 3).getTableHeader();
        JScrollBar   scroll = new JScrollBar(JScrollBar.HORIZONTAL);
        add(header, BorderLayout.NORTH);
        add(scroll, BorderLayout.SOUTH);
        scroll.addMouseListener( new PressedBehavior() );
        header.addMouseListener( new PressedBehavior() );
    }

    static public void main( String[] s ) {
        try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
            SwingUtilities.invokeLater( new Runnable() {
                @Override
                public void run() {
                    JFrame f = new JFrame("Nimbus Pressed Example");
                    f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
                    f.setBounds( 150, 150, 300, 200 );
                    f.getContentPane().add( new Header() );
                    f.setVisible( true );
                }
            });
        } catch( Exception fail ) { /*ignore*/ }
    }
    private class PressedBehavior extends MouseAdapter {
        @Override
        public void mouseReleased( MouseEvent e ) {
            JComponent source = (JComponent)e.getComponent();
            source.putClientProperty( "Nimbus.State", null );
        }
        @Override
        public void mousePressed( MouseEvent e ) {
            JComponent source = (JComponent)e.getComponent();
            source.putClientProperty( "Nimbus.State", "Pressed" );
            //source.invalidate();
            //source.repaint();
        }
    }
}
  • 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-21T18:40:33+00:00Added an answer on May 21, 2026 at 6:40 pm

    technically, you need that state on the rendering component, not on the JTableHeader itself:

        @Override
        public void mousePressed( MouseEvent e ) {
            JComponent source = (JComponent)e.getComponent();
            source.putClientProperty( "Nimbus.State", "Pressed" );
            if (source instanceof JTableHeader) {
                ((JComponent) ((JTableHeader) source).getDefaultRenderer())
                    .putClientProperty("Nimbus.State", "Pressed");
            }
        }
    

    Problem then is that the same instance (of rendering component) is used for all columns, so if you drag a column all appear pressed …

    Edit: couldn’t resist to dig a bit … Nimbus is soooo … lacking, to put it mildly 😉

    Turns out that the defaults indeed have the styles for pressed, what’s missing is the logic to set it. Probably not entirely trivial, because the logic (aka: MouseListener) resides in BasicTableHeaderUI which doesn’t know about subclass’ painter states. The only thingy the logic is supporting (hot needle fix) is rollover-awareness, but not pressed-ness.

    While we can’t hook into the logic (well, we could … but that’s another trick 🙂 we can look for secondary state changes like draggingColumn/resizingColumn (not-bound) properties in JTableHeader and let a custom renderer update itself as appropriate. Here’s a line-out of how-to:

    public static class WrappingRenderer implements TableCellRenderer {
    
        private DefaultTableCellHeaderRenderer delegate;
        private JTableHeader header;
    
        public WrappingRenderer(JTableHeader header) {
            this.header = header;
            this.delegate = (DefaultTableCellHeaderRenderer) header.getDefaultRenderer();
            header.setDefaultRenderer(this);
        }
    
        @Override
        public Component getTableCellRendererComponent(JTable table,
                Object value, boolean isSelected, boolean hasFocus, int row,
                int column) {
            Component comp = delegate.getTableCellRendererComponent(table, 
                    value, isSelected, hasFocus, row, column);
            TableColumn draggedColumn = table.getTableHeader().getDraggedColumn();
            if (draggedColumn != null) {
                if (table.convertColumnIndexToModel(column) == draggedColumn.getModelIndex()) {
                    setNimbusState("Pressed");
                } else {
                    setNimbusState(null);
                }
    
            } else {
                setNimbusState(null);
            }
            // do similar for resizing column
            return comp;
        }
    
        public void setNimbusState(String state) {
            delegate.putClientProperty("Nimbus.State", state);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Checkbox in JTable Header, I am using Nimbus L&F and customize the
I'm trying to create a list that has a header, just like a JTable,
I have following method in my class which extends JTable: protected void setTableCursor(Cursor cursor)
For some reason my header row is not visible. I am using SwingBindings.createJTableBinding to
how can add custom Jtable to GUI Builder netbeans form JPanel panel = new
I'm new to Swing and have been struggling with the JTable component today. Because
I was offering advice on capturing an image of tabular data on Java API
I have a really weird problem with a JScrollPane and a BorderLayout . For
I'm trying to get comfortable with JTables, TableModels, JTableHeaders, renderers, etc. I am trying
public class MainFrame extends JFrame { public DefaultTableModel historyModel; public DefaultTableModel dataModel; public JTable

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.