I've discovered an issue with Windows 10 and Java.
JFrame frame = new JFrame();
frame.setVisible(true);
When I create a new JFrame and show it on the screen, it normally should have the screen coordinates x=0 and y=0. It actually does have those coordinates on windows 10.
But, what is really ugly, is, that it seems all windows in Windows 10 have some kind of "invisible" borders around them. So in this case it looks like the position of the Window is x=7 and y=0:
This is only a simple case where it just looks so ugly. My software has some logic which will "snap" one window onto another when you drag it in the near of the other one. I think you can imagine how ugly it looks if theres a (2*7px=) 14px space between the two windows altough it should be shown for the user as "linked" or "snapped" together.
On Windows 7 this has worked perfectly!
So does somebody know this problem and have any idea, how a workaround could be possible? I think of maybe finding out the current name of the windows theme and operating system name. And if it is "Aero" and "Windows 10", always just calculate x positions with -7px. Would that be somehow possible? Or maybe directly finding out what is the width of the invisible area?
Thanks for any idea about this topic.
To make the frame visible, invoke setVisible(true) on it.
Yes you can draw the borders around the undecorated JFrame. Just simply get the root pane of the JFrame and set its borders by setBorder(Border border) method. As far as I know, this will only shrink down the root pane so it can draw the border inside the frame itself.
This could solve your problem :
public static void setJFrameBounds(JFrame frame, int x, int y, int width, int height) {
Insets insets = ((Window)frame).getInsets();
frame.setBounds(x - insets.left, y, width, height);
}
Edit : the JFrame must be visible before calling the function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With