Java:具有非透明组件的透明Windows? [英] Java: Transparent Windows with non-transparent components?
本文介绍了Java:具有非透明组件的透明Windows?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚刚遇到了实用程序(com.sun.awt.AWTUtilities
),以使您的JFrame 真正透明.文档此处.效果很好.甚至在Linux中,桌面效果随摆动窗口一起打开.但是我也想在透明的JFrame上制作一个不透明的组件.
I just met the utilities (com.sun.awt.AWTUtilities
) to make your JFrame really transparent. Documentation here. This works very good. Even in Linux with the desktop effects with wobbly windows turned on. But I want to make also a non-transparent component on the transparent JFrame.
有人知道,如果可能的话,怎么办?
Does anyone know, if this is possible, how?
这是我使用的代码:
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
及其内容,但是您可以尝试以下和此
IIUC, Translucent Windows applies to the entire java.awt.Window
and contents, but you might try the approach shown below and in this example.
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);
这篇关于Java:具有非透明组件的透明Windows?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文