Setting a JFrame without overlapping with taskbar

╄→尐↘猪︶ㄣ 提交于 2019-12-01 21:34:51

Able to able to fix the above issue with the below code,

Rectangle usableBounds = SunGraphicsEnvironment.getUsableBounds(config.getDevice());
setMaximizedBounds(usableBounds);
setExtendedState(MAXIMIZED_BOTH);

So by getUsableBounds I am able to get the bounds leaving the taskbar. And hence I am using setExtendedState(MAXIMIZED_BOTH) the window is getting updated automatically when I re-size/re-position the taskbar. :-)

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();
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!