2
回答
java1.7如何实现窗体的透明
注册华为云得mate10,2.9折抢先购!>>>   

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

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

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

举报
共有2个答案 最后回答: 5年前

来自官方文档:

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);



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