Aurorachilles
Aurorachilles

Reputation: 81

Can't change JTable Header background color

I want to change the background of the header in jTable in a GUI application. I have tried this as of now

The setForeground works but the setBackground doesn't work.

Any other alternatives to change the Background?

Code I've tried:-

  jTable1.getTableHeader().setOpaque(false);
  jTable1.getTableHeader().setFont(new Font("Calisto MT", Font.BOLD, 40));
  jTable1.getTableHeader().setBackground(new Color(247,99,143));
  jTable1.getTableHeader().setForeground(new Color(12,99,11));

Upvotes: 0

Views: 243

Answers (1)

camickr
camickr

Reputation: 324108

jTable1.getTableHeader().setOpaque(false);

Setting a component non-opaque means the component is transparent so the background is never painted. Get rid of that statement.

All you need is:

jTable1.getTableHeader().setBackground(new Color(247,99,143));

If it doesn't work then the problem could be the LAF you are using.

Upvotes: 2

Related Questions