简体   繁体   English

如何设置未装饰的JFrame的不透明度?

[英]How do I set the opacity of an undecorated JFrame?

I've been having trouble setting the opacity of a window that I would like to be able to fade in gradually. 我一直无法设置希望逐渐淡入的窗口的不透明度。 For now, I'm going to stick with just setting it mostly transparent and keeping it that way. 现在,我将坚持将其设置为大部分透明并保持这种方式。 I've been having trouble doing even that. 我什至在做那件事上都遇到麻烦。 The following code should remove the window decorations and make it mostly transparent. 以下代码应删除窗口装饰,并使其基本透明。 While the decorations are removed, the window still stays completely opaque. 移除装饰后,窗口仍保持完全不透明。

Color transparent = new Color(((float) 1.0), ((float) 1.0), ((float) 1.0), ((float) 0.25));
colorPickerWindow.setUndecorated(true);
colorPickerWindow.setBackground(transparent);

Thanks in advance for you help! 预先感谢您的帮助!

Edit: 编辑:

colorPickerWindow.setOpacity(0.5f);
gives me 给我
 java.lang.UnsupportedOperationException: TRANSLUCENT translucency is not supported. java.lang.UnsupportedOperationException:不支持TRANSLUCENT半透明。 

colorPickerWindow.setOpacity(0.5f);

注意:setOpacity需要一个浮点数。

It seems that not all platforms supports setOpacity (according to http://docs.oracle.com/javase/tutorial/uiswing/misc/trans_shaped_windows.html ). 似乎并非所有平台都支持setOpacity(根据http://docs.oracle.com/javase/tutorial/uiswing/misc/trans_shaped_windows.html )。

Perhaps this can help? 也许这可以帮助? http://www.rgagnon.com/javadetails/java-0265.html http://www.rgagnon.com/javadetails/java-0265.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM