Setting a JFrame without overlapping with taskbar

前端 未结 2 1822

I need to have a undecorated JFrame(setUndecorated(true)) which need to be shown fullscreen, without overlapping with the taskbar.

I have t

2条回答
  •  心在旅途
    2021-01-20 05:42

    final Point x = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint();
    

    Have a separate thread to check whether taskbar get changed. If so update size

    new Thread(new Runnable() {
         @Override
         public void run() {
            if (x.equals(GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint())) {
               Rectangle r = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
               setSize(r.getSize());
            }
            try {
               Thread.sleep(5000);
            } catch (InterruptedException ex) {
               Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
            }
         }
      }).start();
    

提交回复
热议问题