1

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 :)

1
  • 3
    bug???, can you please add BugParades link to your question – mKorbel Jun 26 '12 at 16:29
5

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);
5
  • thanks - I'll have to check out permutations of the screens and where the "taskbar window" is assigned. It will be interesting to see if or how I can find out all of them. Some system have virtual desktops with display spanning taskbars some not, etc. – peterk Jun 27 '12 at 17:06
  • For me, I had already been using the GraphicsConfiguration, but I had not known about the screenInsets. Taking into account the logic from step 2 worked beautifully. And I even have my taskbar on the left. – Pixelstix Apr 4 '17 at 13:33
  • @Guillaume Polet, how to access the toolbar itself to set its Icon_Image? – TiyebM Jan 19 '19 at 23:25
  • @TiMr you can use java.awt.Window.setIconImages for that. It works on Windows and Linux. Not sure about MacOS – Guillaume Polet Jan 21 '19 at 15:28
  • @Guillaume Polet Thank you for your reply, I wanted the taskbar not the toolbar, sorry for that, is there any way to access that. – TiyebM Jan 22 '19 at 10:17
2

Thanks

Here is the code made from above which is calls immediately after the window is maximized by the system. It checks for the taskbars and resizes the window accordinly.

note that the setBounds will "un-maximize" the window as far as Java is concerned so the "getExtendedState()" will return un maximized and I need to maintain my own flag. I also have to cache the last pre-maximized window size so I know where to restore the window to later - all way too messy but it works.

Rectangle bounds;
Rectangle fbounds = frame.getBounds();
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();

// as system maximized this at this point we test the center of the window
// as it should be on the proper screen.
Point p = new Point(fbounds.x + (fbounds.width/2),fbounds.y + (fbounds.height/2));
GraphicsConfiguration graphicsConfiguration = null;
for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices())
{
    if (gd.getDefaultConfiguration().getBounds().contains(p)) {
        graphicsConfiguration = gd.getDefaultConfiguration();
        break;
    }
}
if(graphicsConfiguration != null)
{
    bounds = graphicsConfiguration.getBounds();
    Insets screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(graphicsConfiguration);

    bounds.x += screenInsets.left;
    bounds.y += screenInsets.top;
    bounds.height -= screenInsets.bottom;
    bounds.width -= screenInsets.right;
} else {
    bounds = env.getMaximumWindowBounds();
}
if(fbounds.equals(bounds)) {
    bounds.height -= 1;
}
frame.setBounds(bounds);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.