Install JFrame without overlapping taskbar

I need to have unecorated JFrame ( setUndecorated (true) ), which needs to be shown in full screen, without overlapping the taskbar.

I tried the following solutions.

  • Call setExtendedState (MAXIMIZED_BOTH).

    • Advantage : This works fine as expected, i.e. The window is dynamically configured, except that it has the following problems.
    • Problems The window initially takes up full-screen mode. Although the frame itself is dynamically configured, it overlaps with the taskbar.
  • Tried the solution below as indicated in Does JFrame.setExtendedState (MAXIMIZED_BOTH) work with unordered frames?

    GraphicsConfiguration config = aFrame.getGraphicsConfiguration(); Rectangle usableBounds = SunGraphicsEnvironment.getUsableBounds(config.getDevice()); aFrame.setBounds(0, 0, usableBounds.width, usableBounds.height); 
    • Advantage : I do not get overlapping, and the window looks normal.
    • Question : The window does not adjust dynamically when changing the position / size of the taskbar.

Any help would be greatly appreciated.

I was thinking about design. But not sure of its capabilities. I can use setBounds (). But then I need my frame to be notified when the taskbar is configured or changed. Is there any way?

+3
source share
2 answers

Ability to fix the above problem with the code below,

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

So getUsableBounds I can get the borders coming out of the taskbar. And so I use setExtendedState(MAXIMIZED_BOTH) , the window is automatically updated when I re-edit / rearrange the taskbar. setExtendedState(MAXIMIZED_BOTH)

+3
source
 final Point x = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint(); 

You have a separate thread to check if the taskbar has changed. If so, update the 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(); 
0
source

Source: https://habr.com/ru/post/1445880/


All Articles