java1.7如何实现窗体的透明

省委书记沙瑞金 发布于 2012/11/19 21:51
阅读 351
收藏 1

java1.7如何实现窗体的透明,

com.sun.awt.AWTUtilities.setWindowOpacity(this, 0.6f); 

在eclipse中会报错!怎么办啊!

加载中
0
逝水fox
逝水fox

来自官方文档:

The following conditions must be met in order to set the opacity value less than 1.0f: 
1.The TRANSLUCENT translucency must be supported by the underlying system 
2.The window must be undecorated (see setUndecorated(boolean) and Dialog.setUndecorated(boolean))
3.The window must not be in full-screen mode (see GraphicsDevice.setFullScreenWindow(Window)) 
If the requested opacity value is less than 1.0f, and any of the above conditions are not met, the window opacity will not change, and the IllegalComponentStateException will be thrown.
换句话说在设置透明效果前要执行setUndecorated(true);



0
落落的月
落落的月
com.sun.awt.AWTUtilities.setWindowOpacity(this, 0.6f); 报错是因为这个包里面的方法不属于jdk正式版本,也就是不能保证下个版本还存在 所以编译器会拒绝,你可以在eclipse的首选项里设置编译级别为WARN,(原本为ERROR,意思是类似这种的包报错)
返回顶部
顶部