javaswinglook-and-feel

Java - How to avoid covering the taskbar with undecorated or custom LookAndFeel Window?


Yes some questions get close :)

There is a Bug in Java ( been around and reported since 2011, seems like there is no effort being made to fix it either - should be handled on the native side of the VM)

That is when you maximize an "undecorated" window, or a window drawn wihth a PLAF look and feel, it will cover the windows taskbar. Fine - desirable when you want it, but when you do want the taskbar maximized windows cover it. setting the "always on top" proerty doesn make any difference.

Yes one can resize a window BUT one has to know where the task bar is, or the size of the screen minus the taskbar - know how to do that?

and one needs to know you are maximizing on a screen without a taskbar if that is being done. and if on a multimonitor virtual desktop ...

Any ideas :)


Solution

  • Yes one can resize a window BUT one has to know where the task bar is, or the size of the screen minus the taskbar - know how to do that?

    Yes:

    1.Look up the graphic device you are on (assuming p is a Point of the Screen you are looking for):

    GraphicsConfiguration graphicsConfiguration = null;
    for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) {
        if (gd.getDefaultConfiguration().getBounds().contains(p)) {
            graphicsConfiguration = gd.getDefaultConfiguration();
            break;
        }
    }
    

    2.Look at the screen bounds (watch out that some bounds location are negative with multiple screens - for example, if you have a secondary screen which is on the left of your main screen), the screen size and the "Insets" of the screen which are usually the taskbar and/or other graphical artifacts:

    Rectangle screenBounds = graphicsConfiguration.getBounds();
    Dimension screenSize = screenBounds.getSize();
    Insets screenInsets = Toolkit.getDefaultToolkit()
         .getScreenInsets(graphicsConfiguration);