在Java 6和Java 7中使用透明窗口 [英] Using transparent window in both Java 6 and Java 7

查看:60
本文介绍了在Java 6和Java 7中使用透明窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Java 6(1.6.0_24)中开发应用程序,该应用程序使用透明的JFrame来获取消失的动画.这是我的代码:

I'm developing application in Java 6 (1.6.0_24) which using transparent JFrame to get disappearing animation. Here is my code:

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

它在我的机器上可以正常工作,但是当我在安装了Java 7的另一台PC上对其进行测试时,却出现了以下错误:

It works fine on my machine, but when I tested it on another PC with Java 7 installed I have fallowing error:

 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方法.

I think it is because in Java 7 I should use Window.setOpacity(...) instead of AWTUtilities methods.

可以在Java 6应用中使用透明性,该透明性将在Java 7上运行?

It is possible to use transparency in Java 6 app, that will run on Java 7 ?

推荐答案

请参见

See How to Create Translucent and Shaped Windows.. It mentions a "per pixel" translucency that you can leverage to make a window with java 7 that has the look and feel of the translucent window from java 6 which is no longer available. So basically you'd have to code to accommodate either, or you could go with a "uniform translucency" which works with both.

这篇关于在Java 6和Java 7中使用透明窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆