![](/img/trans.png)
[英]How to add non-Transparent components to Transparent JFrame in java 1.5?
[英]Java: Transparent Windows with non-transparent components?
我刚刚遇到了实用程序( com.sun.awt.AWTUtilities
),以使您的JFrame 真正透明。 文档在这里 。 这非常好。 即使在Linux中,桌面效果也会打开摇摆不定的窗口。 但是我想在透明的JFrame上制作一个非透明的组件。
有谁知道,如果有可能,怎么样?
这是我使用的代码:
import com.sun.awt.AWTUtilities;
/* "this" is the JFrame */
this.setUndecorated(true);
AWTUtilities.setWindowOpaque(this, true);
AWTUtilities.setWindowOpacity(this, 0.5f);
AWTUtilities.setWindowShape(this, new RoundRectangle2D.Float(0f, 0f, (float) getWidth(), (float) getHeight(), 15f, 15f));
IIUC, 半透明Windows适用于整个java.awt.Window
和内容,但您可以尝试下面和此示例中显示的方法。
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setBackground(new Color(0f, 0f, 0f, 0.1f));
f.setUndecorated(true);
f.add(new JLabel("<html>Testing<br>1, 2, 3</html>"));
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
你想要做的是将setWindowOpaque
为false
并使用低alpha绘制背景(如果你想要完全透明,则绘制0 alpha)。 组件仍将被绘制为不透明。 请参阅此文章并查看每像素半透明度 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.