[英]Java: Transparent Windows with non-transparent components?
I just met the utilities ( com.sun.awt.AWTUtilities
) to make your JFrame really transparent. 我刚刚遇到了实用程序(
com.sun.awt.AWTUtilities
),以使您的JFrame 真正透明。 Documentation here . 文档在这里 。 This works very good.
这非常好。 Even in Linux with the desktop effects with wobbly windows turned on.
即使在Linux中,桌面效果也会打开摇摆不定的窗口。 But I want to make also a non-transparent component on the transparent JFrame.
但是我想在透明的JFrame上制作一个非透明的组件。
Does anyone know, if this is possible, how? 有谁知道,如果有可能,怎么样?
Here is the code I used: 这是我使用的代码:
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, Translucent Windows applies to the entire java.awt.Window
and contents, but you might try the approach shown below and in this example . 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);
What you want to do is setWindowOpaque
to false
and draw the background with low alpha (or 0 alpha if you want complete transparency). 你想要做的是将
setWindowOpaque
为false
并使用低alpha绘制背景(如果你想要完全透明,则绘制0 alpha)。 The components will still be drawn opaque. 组件仍将被绘制为不透明。 See this article and look at per-pixel translucency .
请参阅此文章并查看每像素半透明度 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.