jjzjj

java - The Java Tutorials Translucent Window example 是否会给那些玩 jdk7 的人带来麻烦?

coder 2024-03-05 原文

这是 example .

如果您在比方说支持 jdk7 的 NetBeans IDE 7.0 中构建并运行 TranslucentWindow,您将得到以下异常:

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),那么它不会抛出异常并会创建一个半透明窗口,尽管没有任何装饰(这很痛苦) .这是正常的吗?这段代码不应该“开箱即用”吗?我是不是忽略了什么?

编辑

为什么他们的半透明窗口看起来是经过装饰的,或者这是自定义渲染?

它是什么......

它应该是什么......

最佳答案

来自 JavaDocs for java.awt.frame.setOpacity() in JDK7 :

The following conditions must be met in order to set the opacity value less than 1.0f:

  • The TRANSLUCENT translucency must be supported by the underlying system
  • The window must be undecorated (see setUndecorated(boolean) and Dialog.setUndecorated(boolean))
  • 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.

您看到的行为已记录在案并且是预期的行为。

关于java - The Java Tutorials Translucent Window example 是否会给那些玩 jdk7 的人带来麻烦?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6259269/

有关java - The Java Tutorials Translucent Window example 是否会给那些玩 jdk7 的人带来麻烦?的更多相关文章

随机推荐