This is not a Java issue, but a user interface design issue. The application that I am currently developing requires at least 1024 by 768 to meet all the requirements. But if it does not need space, then why start with this size? Why not let the user maximize the window if he wants to? The user interface should work as many different sizes of the display as possible.
My policy is that the best window size is the smallest, which still allows the user to do everything he needs to work with the program. Now back to Java: when creating the swing application, call pack () after placing all the components in the containers. If for some reason I feel the package is too tight, then I can add a little to the width or height immediately after calling the package.
If you need to know the dimensions of the display you are working on, use this:
Toolkit toolkit = Toolkit.getDefaultToolkit(); Dimension screensize = toolkit.getScreenSize();
With swing, you can also set the preferred size for the components, and this will affect the size that they occupy after calling pack ().
Thorn source share