这是示例。
如果您TranslucentWindow
在支持 jdk7 的 NetBeans IDE 7.0 中构建并运行,您将收到以下异常:
Exception in thread "AWT-EventQueue-0" java.awt.IllegalComponentStateException: The frame is decorated
at java.awt.Frame.setOpacity(Frame.java:960)
at main.TranslucentWindow.<init>(TranslucentWindow.java:23)
at main.TranslucentWindow$1.run(TranslucentWindow.java:47)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:705)
at java.awt.EventQueue.access$000(EventQueue.java:101)
at java.awt.EventQueue$3.run(EventQueue.java:666)
at java.awt.EventQueue$3.run(EventQueue.java:664)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:675)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
BUILD SUCCESSFUL (total time: 1 second)
根据此堆栈跟踪,有问题的行是tw.setOpacity(0.55f)
. 但是,正如错误所示,如果您setUndecorated(true)
在框架上调用,那么它不会抛出异常并会创建一个半透明的窗口,尽管没有任何装饰(这很痛苦)。这是正常的吗?这段代码不应该“开箱即用”吗?我忽略了什么吗?
编辑
为什么他们的半透明窗口看起来装饰,或者这是自定义渲染?
这是什么...
应该是什么...