Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make the background of a JTable transparent? [duplicate]

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.

like image 400
Olivier Faucheux Avatar asked Jul 23 '12 09:07

Olivier Faucheux


People also ask

How do I make a table background transparent in HTML?

opacity: . 0; in different combinations in the script i.e. after each line of code for the colour or only certain ones but not others but the whole table and the text go completely transparent and not just the background colour.


1 Answers

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...

like image 148
Olivier Faucheux Avatar answered Oct 14 '22 10:10

Olivier Faucheux