java fullscreen window with transparency

只愿长相守 提交于 2019-12-04 04:44:52
  • is possible only with visible TaskBar e.i.

.

GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
  • otherwise you got and exception

.

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: 
The effects for full-screen windows are not supported. 

or by using brutte_force to DirectX freezed my PC twicw, only power_off to save PC's GPU

import com.sun.awt.AWTUtilities;
import java.awt.Dimension;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class JFrameOpacityExample {

    private JFrame myFrame = new JFrame("Test Frame");
    private boolean opacity = true;
    private boolean resize = true;
    private JButton button = new JButton("Opacity");
    private JButton button1 = new JButton("Resize");

    public JFrameOpacityExample() {
        button.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent evt) {
                Object src = evt.getSource();
                if (opacity) {
                    AWTUtilities.setWindowOpacity(myFrame, 0.50f);
                    opacity = false;
                } else {
                    AWTUtilities.setWindowOpacity(myFrame, 1.0f);
                    opacity = true;
                }
            }
        });
        button1.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent evt) {
                Object src = evt.getSource();
                if (resize) {
                    Rectangle dim = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
                    int h = dim.height;
                    int w = dim.width;
                    myFrame.setBounds(00, 00, w, h);
                    resize = false;
                } else {
                    myFrame.setBounds(100, 100, 400, 400);
                    resize = true;
                }
            }
        });
        JPanel panel = new JPanel();
        panel.add(button);
        panel.add(button1);
        myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        myFrame.add(panel);
        myFrame.setSize(400, 400);
        myFrame.setVisible(true);
    }

    public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                JFrameOpacityExample jFrameOpacityExample = new JFrameOpacityExample();
            }
        });
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!