在Java 6和Java 7使用透明窗口(Using transparent window in b

2019-06-26 09:21发布

我在开发应用程序Java 6 ,其使用透明(1.6.0_24) JFrame获得消失动画。 这里是我的代码:

public static void slowDisappearWindowAction(Window source, int milisSlow, int milisFast) throws InterruptedException{
    float level = 1.0f;
    //slow effect -> 50%
    for(int i=0; i<8 ; i++){
        level=level-0.05f;
        AWTUtilities.setWindowOpacity(source,level);
        Thread.sleep(milisSlow);
    }
    //fast effect -> 0% 
    for(int i=0; i<8 ; i++){
        level=level-0.05f;
        AWTUtilities.setWindowOpacity(source,level);
        Thread.sleep(milisFast);
    }
    AWTUtilities.setWindowOpacity(source,0.1f);
}

它工作正常,我的机器上,但是当我测试它与另一台PC上Java 7安装我已经撂荒错误:

 Exception in thread "AWT-EventQueue-0" java.awt.IllegalComponentStateException:
 The frame is decorated
    at java.awt.Frame.setOpacity(Unknown Source)
    at java.awt.Window$1.setOpacity(Unknown Source)
    at com.sun.awt.AWTUtilities.setWindowOpacity(Unknown Source)
    at pl.design.bead.pattern.model.window.WindowHelper.slowDisappearWindowAction(WindowHelper.java:21)
    at pl.design.bead.pattern.forms.MainForm$ExitController.windowClosing(MainForm.java:123)
    at java.awt.AWTEventMulticaster.windowClosing(Unknown Source)
    at java.awt.Window.processWindowEvent(Unknown Source)
    at javax.swing.JFrame.processWindowEvent(Unknown Source)
    at java.awt.Window.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$000(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

我想,这是因为在Java 7 ,我应该使用Window.setOpacity(...)而不是AWTUtilities方法。

它是可以使用的透明度在Java 6的应用程序,将上运行Java 7

Answer 1:

请参阅如何创建透明和不规则窗口 。它提到了“每个像素”半透明,你可以利用,使与具有从Java 6的半透明窗口,它不再可用的外观和感觉的Java 7的窗口。 所以基本上你不得不代码,使其适合,或者你可以用一个“统一的透明度”,这与两个工作去了。



文章来源: Using transparent window in both Java 6 and Java 7