简体   繁体   中英

AWTUtilities setWindowOpaque causing problems

I have a modal JDialog that I set non-opaque with a call to the com.sun.awt.AWTUtilities method, setWindowOpaque(this, false) .

I encounter problems when I set the modal JDialog to be non-opaque. For example, when I click on a button a non-opaque dialog, it pop up correctly but after a couple of opening and closing of the dialog, it does open. It is not visible; and, since it is modal, we can't click on the button contained in the parent panel. It's like it is frozen, but that's only because of the modal dialog.

If I remove the call to the method setWindowOpaque(this, false) , it works without any problem.

Does anyone know what is going on?

I am using Java version "1.6.0_26" on Windows XP.

Thanks.

Ok, had a similar problem, sometimes the window was not responding, or transparency was broken... weird problems.

The solution, at least for me, was calling new TransparentWindow() inside invokeLater :

SwingUtilities.invokeLater(new Runnable() {
    @Override
    public void run() {
        TransparentWindow w = new TransparentWindow();
        w.setVisible(true);
    }
});

TransparentWindow is a class extending JWindow that uses com.sun.awt.AWTUtilities.setWindowOpaque(window,false); to create a transparent window with rounded transparent corners as explained here: Soft clipping and per-pixel translucency for Swing windows

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM