How to change the background color of a JTable in java?

1

I want to change the gray color that has a JTable default in netbeans.

How can I do it?

    
asked by Giovani Preciado Ortiz 13.07.2017 в 20:26
source

1 answer

2

In general, you should be able to change the background color with

Color myColor = new Color(255,255,208);
table.setBackground(myColor);

But depending on how your code really is, this may not work directly. If you have the table within JScrollPane and you have told the table to fill the panel with a code of this type:

JScrollPane scroll = new JScrollPane(table);
table.setFillsViewportHeight(true);

You will have to change the color of the ViewPort

scroll.getViewport().setBackground(myColor);

This may vary a bit depending on whether you have defined the table as opaque or not ( table.setOpaque(false); ), but playing with these variables you should be able to change the background

    
answered by 13.07.2017 в 21:51