java 如何使 JTable 的背景透明?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11609900/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 05:46:39  来源:igfitidea点击:

How to make the background of a JTable transparent?

javaswingjtabletransparent

提问by Olivier Faucheux

Possible Duplicate:
Java swing Table transparency

可能的重复:
Java swing 表透明度

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

使 JTable 背景透明并不是那么容易。我只想看到我的单元格的文本内容。

回答by Olivier Faucheux

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:

如果表在 a 中ScrollPane,它也是透明的:

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

为了一个简单的结果,相当大的工作......