Swing实现全屏(覆盖任务栏和不覆盖任务栏)

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/jacke121/article/details/72890247


Swing实现全屏(覆盖任务栏和不覆盖任务栏)

   
任务栏不全屏
import javax.swing.JButton;
import javax.swing.JFrame;

public class FullScreenTest2 {
    public static void main(String[] args) {
        final JFrame f = new JFrame("FullScreenTest");
        final JButton btn = new JButton("FullScreen");
        btn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (btn.getText().equals("FullScreen")) {
                    f.dispose();
                    f.setUndecorated(true);

                    Dimension screenSize = Toolkit.getDefaultToolkit()
                            .getScreenSize();
                    Rectangle bounds = new Rectangle(screenSize);
                    Insets insets = Toolkit.getDefaultToolkit()
                            .getScreenInsets(f.getGraphicsConfiguration());
                    bounds.x += insets.left;
                    bounds.y += insets.top;
                    bounds.width -= insets.left + insets.right;
                    bounds.height -= insets.top + insets.bottom;

                    f.setBounds(bounds);
                    f.setVisible(true);
     
展开阅读全文

没有更多推荐了,返回首页