Context
In Microsoft Windows, I am able make an application's window occupy half the of display by using the shortcuts:
- ⊞ Win + ←
- ⊞ Win + →
These shortcuts cause a "split screen," as seen in this screenshot:
I would like to programmatically size and position a JFrame
in the same manner. However, I do not know how to achieve the desired result.
I thought that solution was:
- Set the frame's width to the half the screen width.
- Set the frame's height to the screen height (minus the taskbar height).
- Set the frame's position to (0,0).
Here is an MCVE:
JFrame testFrame = new JFrame();
Rectangle windowBounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
testFrame.setSize(windowBounds.width / 2, windowBounds.height);
testFrame.setLocation((int) windowBounds.getMinX(), (int) windowBounds.getMinY());
testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
testFrame.setVisible(true);
This nearly works, but the window has small margins on the bottom and the left:
Question
On a Windows computer, is there a way to programmatically split the screen using Java, or perhaps JNI?
windowBounds.getMinX()
andwindowBounds.getMinY()
, as well asgetMaximumWindowBounds()
, and make sure they're reasonable.