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

举报
风吹稻花香 发表于 2021/06/05 00:55:37 2021/06/05
【摘要】   Swing实现全屏(覆盖任务栏和不覆盖任务栏)    任务栏不全屏 import javax.swing.JButton;import javax.swing.JFrame; public class FullScreenTest2 {    public static v...

 

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

   
任务栏不全屏

   
  1. import javax.swing.JButton;
  2. import javax.swing.JFrame;
  3. public class FullScreenTest2 {
  4.     public static void main(String[] args) {
  5.         final JFrame f = new JFrame("FullScreenTest");
  6.         final JButton btn = new JButton("FullScreen");
  7.         btn.addActionListener(new ActionListener() {
  8.             public void actionPerformed(ActionEvent e) {
  9.                 if (btn.getText().equals("FullScreen")) {
  10.                     f.dispose();
  11.                     f.setUndecorated(true);
  12.                     Dimension screenSize = Toolkit.getDefaultToolkit()
  13.                             .getScreenSize();
  14.                     Rectangle bounds = new Rectangle(screenSize);
  15.                     Insets insets = Toolkit.getDefaultToolkit()
  16.                             .getScreenInsets(f.getGraphicsConfiguration());
  17.                     bounds.x += insets.left;
  18.                     bounds.y += insets.top;
  19.                     bounds.width -= insets.left + insets.right;
  20.                     bounds.height -= insets.top + insets.bottom;
  21.                     f.setBounds(bounds);
  22.                     f.setVisible(true);
  23.                     btn.setText("NormalMode");
  24.                 } else {
  25.                     f.dispose();
  26.                     f.setUndecorated(false);
  27.                     f.pack();
  28.                     f.setLocationRelativeTo(null);
  29.                     f.setVisible(true);
  30.                     btn.setText("FullScreen");
  31.                 }
  32.             }
  33.         });
  34.         f.getContentPane().setLayout(new FlowLayout());
  35.         f.getContentPane().add(btn);
  36.         f.pack();
  37.         f.setLocationRelativeTo(null);
  38.         f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  39.         f.setVisible(true);
  40.     }
  41. }



任务栏全屏


   
  1. import java.awt.*;
  2. import java.awt.event.ActionEvent;
  3. import java.awt.event.ActionListener;
  4. import javax.swing.JButton;
  5. import javax.swing.JFrame;
  6. public class FullScreenTest2 {
  7.     public static void main(String[] args) {
  8.         final JFrame f = new JFrame("FullScreenTest");
  9.         final JButton btn = new JButton("FullScreen");
  10.         btn.addActionListener(new ActionListener() {
  11.             public void actionPerformed(ActionEvent e) {
  12.                 if (btn.getText().equals("FullScreen")) {
  13.                     f.dispose();
  14.                     f.setUndecorated(true);
  15.                     Dimension screenSize = Toolkit.getDefaultToolkit()
  16.                             .getScreenSize();
  17.                     Rectangle bounds = new Rectangle(screenSize);
  18.                     Insets insets = Toolkit.getDefaultToolkit()
  19.                             .getScreenInsets(f.getGraphicsConfiguration());
  20.                     bounds.x += insets.left;
  21.                     bounds.y += insets.top;
  22.                     bounds.width -= insets.left + insets.right;
  23.                     bounds.height -= insets.top + insets.bottom;
  24.                     f.setBounds(bounds);
  25.                     f.setVisible(true);
  26.                     btn.setText("NormalMode");
  27.                 } else {
  28.                     f.dispose();
  29.                     f.setUndecorated(false);
  30.                     f.pack();
  31.                     f.setLocationRelativeTo(null);
  32.                     f.setVisible(true);
  33.                     btn.setText("FullScreen");
  34.                 }
  35.             }
  36.         });
  37.         f.getContentPane().setLayout(new FlowLayout());
  38.         f.getContentPane().add(btn);
  39.         f.pack();
  40.         f.setLocationRelativeTo(null);
  41.         f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  42.         f.setVisible(true);
  43.     }
  44. }

 

 

 

 

文章来源: blog.csdn.net,作者:网奇,版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/jacke121/article/details/72890247

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。