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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:00:41+00:00 2026-05-25T16:00:41+00:00

If you want to add a custom renderer, normally, you’d either extend some JComponent

  • 0

If you want to add a custom renderer, normally, you’d either extend some JComponent (like JLabel) and implement TableCellRenderer, or you’d extend DefaultTableCellRenderer. However, in either case, what I find is that the cell style is completely overridden.

What I’d really like is to be able to paint the default L&F background and then paint on top of it using other L&F defaults like foreground color and font.

So, here’s what I tried to do. First, the class:

public class IntervalHeaderRenderer extends JLabel implements TableCellRenderer {

    private TableCellRenderer delegate;
    private Component component;

    public IntervalHeaderRenderer(TableCellRenderer defaultRenderer)
    {
        this.delegate = defaultRenderer;
    }

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value,
                           boolean isSelected, boolean hasFocus, int row, int column)
    {
        component = delegate.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);

        // Maybe override some settings.  
        // You could make the label bold, for instance.

        return component;
        // return this;
    }

    @Override
    public void paint(Graphics g) {
        // What I really want to do is paint the original component
        component.paint(g);
        // And then draw on top of it.
    }
}

And then I override the cell (header) renderer like this:

TableCellRenderer renderer = table.getTableHeader().getDefaultRenderer();
table.getColumnModel().getColumn(1).setHeaderRenderer(new IntervalHeaderRenderer(renderer));

I’m basically just following the suggestions here: TableCellRenderer, Part 2 – How To Create A Custom Renderer

If I return component, it renders as if I had overridden nothing. That is, I get the header with the label I had programmed with the chosen L&F background and style and everything. But, of course, there no way to render my stuff afterwards.

On the other hand, if I return this, then I get absolutely nothing. Mac native L&F gives me a white background, while Nimbus gives me a solid of some other color.

I’m clearly missing something. Are there other methods on the Component that I need to override and forward to the original? How does the default component get drawn if not by overriding paint? (I’ve also tried overriding paintComponent. No difference.)

Is there another way to do this? I’ve thought about trying to drop a native styled JPanel in there and then making a custom (transparent background) component its child, although I’m not sure about how to go about it, and I’m not really sure I’d get the native L&F table header background anyhow. In fact, I highly doubt I’d get the native header style, just the native JPanel style.

Basically, I need a custom table header (and separately, the cells too, actually), but I want to avoid messing too much with the native L&F.

Thanks!

  • 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-25T16:00:41+00:00Added an answer on May 25, 2026 at 4:00 pm

    You might look at the approach taken in updateUI() in SelectAllHeaderTest, as well as the helpful caveats in the accepted answer.

    Addendum: By way of explanation, note that the header’s appearance falls under the aegis of the host platform’s corresponding UI delegate, usually derived from TableHeaderUI. You may want to confine your changes to the UIManager Defaults common to popular Look & Feel implementations. Also, don’t override paint(). I would avoid overriding paintComponent(); and, if necessary, override paintIcon(), as shown in TableSorter.

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

Sidebar

Related Questions

I want to add some custom roads using google maps api (i.e. off-road routes,
I want to add custom typed properties to a webcontrol, like for example EditRowStyle
I want add my custom sidebar next right column all page. Please check this
I want to add custom jump list entries to my application in Windows 7.
I want to add custom attribute settings to a generated anchor link of Wordpress.
I am using C#.net I want to add custom edit/delete buttons to my GridView1
I want to add a custom configuration section in my app.config file. Is there
I want to add a custom model method to the admin filter, however it
I want to add a custom message once someone saves a specific content-type telling
I want to add a custom overlay (a png) in the middle of the

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.