How to make the background of a JTable transparent

2019-01-24 16:12发布

问题:

Possible Duplicate:
Java swing Table transparency

It is not so easy to make a JTable background transparent. I want to see only the text content of my cells.

回答1:

The table will be transparent if neither itself nor the cells are opaque:

table.setOpaque(false);
((DefaultTableCellRenderer)table.getDefaultRenderer(Object.class)).setOpaque(false);

If the table is in a ScrollPane, it is to make transparent as well:

scrollPane.setOpaque(false);
scrollPane.getViewport().setOpaque(false);

At least, you can remove the grid lines:

table.setShowGrid(false);

Quite a big work for a simply result...