gpt4 book ai didi

java - 如何使 JLayeredPane() 和 JPanel() 透明?它总是显示 super 窗口的背景

转载 作者:搜寻专家 更新时间:2023-11-01 02:53:29 25 4
gpt4 key购买 nike

我怎样才能完全使这个灰色面板透明,这样我就只能看到按钮“测试”而看不到灰色框(JPanel 或JLayeredPane)

屏幕截图:enter image description here

public class win extends JWindow 
{
...

public win()
{
super(new JFrame());
layers = new JLayeredPane();
button = new JButton("close");

this.setLayout (new BorderLayout ());
..

button.setBackground(Color.RED);
button.setSize(200,200);
button.setLocation(0,20);
this.add("North", button);

JPanel p = new JPanel();
p.setOpaque(false);
p.setSize(300, 200);
p.setLocation(0, 0);
p.add(new JButton("Test"));

layers.add(p, new Integer(1));
layers.setSize(400,300);
layers.setLocation(400,50);
layers.setOpaque(false);
this.add("North", layers);

canvas.setSize(screenSize.width,screenSize.height);
this.add("North",canvas);
//com.sun.awt.AWTUtilities.setWindowOpacity(this, 0.5f); // gives error in my Java version

}
}

跟进:按照建议安装,但还没有成功。

ERROR not solved: Exception in thread "main" java.lang.UnsupportedOperationException: The TRANSLUCENT translucency kind is not supported.

Installed:
compiz-gnome.i686 0:0.9.4-2.fc15

Dependency Installed:
compiz-gtk.i686 0:0.9.4-2.fc15 compiz-plugins-main.i686 0:0.9.4-1.fc15
libcompizconfig.i686 0:0.9.4-1.fc15 protobuf.i686 0:2.3.0-7.fc15

Complete!
You have mail in /var/spool/mail/root
[root@example ~]# xdpyinfo | grep -i render
RENDER
You have mail in /var/spool/mail/root
[root@example ~]# xdpyinfo | grep -i comp
Composite
XVideo-MotionCompensation
[root@example ~]#

最佳答案

参见 this articlethis article .请注意,并非所有环境都支持本文中描述的所有功能(半透明、每像素透明度等)。

编辑:在我的系统(Ubuntu 10.04.2 LTS,Sun java 1.6.0_26)上,以下代码:

  System.out.println("TRANSLUCENT supported:          " + AWTUtilities.isTranslucencySupported(AWTUtilities.Translucency.TRANSLUCENT));
System.out.println("PERPIXEL_TRANSPARENT supported: " + AWTUtilities.isTranslucencySupported(AWTUtilities.Translucency.PERPIXEL_TRANSPARENT));
System.out.println("PERPIXEL_TRANSLUCENT supported: " + AWTUtilities.isTranslucencySupported(AWTUtilities.Translucency.PERPIXEL_TRANSLUCENT));

给出:

TRANSLUCENT supported:          false
PERPIXEL_TRANSPARENT supported: true
PERPIXEL_TRANSLUCENT supported: true

EDIT2: 灵感来自 this discussion ,我刚刚安装并配置了 compiz,现在上面链接的第二篇文章中 Web 启动应用程序的“恒定不透明度级别” slider 突然可以移动到小于 100% 的值,演示框架实际上是半透明。此外,上面显示的代码片段现在为所有三种半透明/透明度打印 trueAWTUtilities.setWindowOpacity(..) 不再抛出任何异常,而是生成一个透明窗口。

关于java - 如何使 JLayeredPane() 和 JPanel() 透明?它总是显示 super 窗口的背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6712012/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com