0

我使用此示例创建窗口透明度,但在 XP OS 中使用 1.6 更新 27 进行测试时,当我尝试按下标题栏时出现闪烁问题,但在 Windows 7 操作系统中也出现了同样的问题。这有什么问题?

import java.awt.*;
import java.awt.event.MouseAdapter;
import javax.swing.*;
import com.sun.awt.AWTUtilities;
//import static java.awt.GraphicsDevice.WindowTranslucency.*;

public class TranslucentWindowDemo extends JFrame
{
    public TranslucentWindowDemo()
    {
        super( "TranslucentWindow" );
        setLayout( new GridBagLayout() );

        setSize( 300, 200 );
        setLocationRelativeTo( null );
        setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

        // Add a sample button.
        add( new JButton( "I am a Button" ) );
    }

    public static void main( String[] args )
    {
        // Determine if the GraphicsDevice supports translucency.
//      GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
//      GraphicsDevice gd = ge.getDefaultScreenDevice();

        // If translucent windows aren't supported, exit.
        /*if ( !gd.isWindowTranslucencySupported( TRANSLUCENT ) )
        {
            System.err.println( "Translucency is not supported" );
            System.exit( 0 );
        }*/

        JFrame.setDefaultLookAndFeelDecorated( true );

        final TranslucentWindowDemo tw = new TranslucentWindowDemo();
        //AWTUtilities.setWindowOpacity( tw , 0.55f );
        tw.setVisible( true );

        tw.addMouseListener( new MouseAdapter() {
            public void mousePressed( java.awt.event.MouseEvent e )
            {
                SwingUtilities.invokeLater( new Runnable() {
                    public void run()
                    {
                        // Set the window to 55% opaque (45% translucent).
                        AWTUtilities.setWindowOpacity( tw , 0.55f );
//                       tw.setOpacity(0.85f);
                    }
                } );
            };

            public void mouseReleased( java.awt.event.MouseEvent e )
            {
                SwingUtilities.invokeLater( new Runnable() {
                    public void run()
                    {

                        // Set the window to 55% opaque (45% translucent).
                        AWTUtilities.setWindowOpacity( tw, 1.0f );
//                       tw.setOpacity(1.0f);
                    }
                } );

            };
        } );
    }
}

4

0 回答 0