Java swing JFrame size returns a larger screen size
When investigating some problems in my application, I found something strange
Basically, the sscce should prove this problem:
public class MainFrame extends JFrame { public MainFrame() { setDefaultCloSEOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setExtendedState(JFrame.MAXIMIZED_BOTH); pack(); } } public class Main { public static void main(String[] args) { MainFrame mf = new MainFrame(); mf.setVisible(true); System.out.println(mf.getSize()); } }
Somehow, in my 1280 × On 1024 resolution displays, this results in:
java. awt. In dimension [width = 1296, height = 1010]
Who knows what's going on? Especially the fact that the width is higher than what should happen
to greet.
Solution
The window border may be 8 pixels wide When maximized, windows resizes the window so that the width of the client area reaches 1280 pixels Then the entire width of the window is 8 1280 pixels = 1296 pixels The same is true of height
When using the extended desktop on multiple monitors, it can sometimes be noted that when the window is maximized on one screen, the border of the window can be seen on adjacent screens