I have a (somewhat philosophical) question relatively to Swing, or to GUI programming in general. Are there recognized best practices on where to locate the JFrame
instances used in the application?
- Where should the first and main frame be located? Always at the center (
setLocationRelativeTo(null)
)? - Where should a child
JFrame
be located? Relatively to its parentJFrame
, at the center of the screen, wherever we want?
I have always assumed there were some best practices, kind of a "GUI bible" about this, am I wrong and should I (gasp) arbitrarily decide what to do?
I've usually let the platform decide by calling:
This lets the window "appear at the default location for the native windowing system". For more on this: Window API
What I always do is start at the center of the screen for main frame, or at the center of a parent for child frames, I record this location. Then as users move the frames to wherever they want I record the new location and when next the app is started, I use the last location to place the frame.
Here is an example that incorporates the advice of:
Hovercraft Full Of Eels - set location by platform.
But goes on to add 2 tweaks:
The 4 points combined offer the best user experience!
Not sure if there's a best practice as it is very subjective.
Setting it at the center and allowing users to change it to the location they like seems to be the ideal one.
As regards to the child frame, depending on its size, in the center of the parent frame, or just something easy to use.