How can I change JTable's header background color?

Stefanos Kargas picture Stefanos Kargas · Oct 15, 2011 · Viewed 43.7k times · Source

I've tried:

table.getTableHeader().setBackground(Color.BLACK);

Doesn't work.

EDIT: This code doesn't work in my project only. Works in other projects. I may have changed a property that stops the color from changing. Or maybe NetBeans has some property which keeps the default colors. I've noticed something else. The color of the header in my project is shining in a different way. In the examples where the color change works, I see different graphics.

EDIT 2: Something else. I noticed that the buttons won't change color either. Must be something generic. Hope this helps. Unfortunately SSCCE won't work in this case, because I can't recreate the problem. I am surely using the right component names.

Answer

Venkatesh Bandarapu picture Venkatesh Bandarapu · Nov 27, 2014

Try this:

table.getTableHeader().setOpaque(false);

then set the background of jtable header

table.getTableHeader().setBackground(Color.BLACK);