Reputation: 31070
what would be a standard/optimal java swing gui (eg. JFrame) dimension when rendering on a user screen?
would it be wise to set preferred size to 1024 x 768 or 800 x600 or something similar?
should we set preferred size according to the screen size? or is that not a good route?
Upvotes: 4
Views: 3739
Reputation: 2496
According to the statistics given by w3schools here: http://www.w3schools.com/browsers/browsers_display.asp , it is safe to assume people have a screen resolution of 1024x768 or more.
If you are building a GUI with a fixed size, I'd recommend staying a bit under this resolution, in order to accomodate users with a double-height taskbar or a lateral taskbar (try to see for yourself what fits, something like 900x700 could be good enough).
If your window is resizeable then I would try different sizes to see what looks nicer. Depending on the layout of your application, too small will look too busy, too large could make visual elements too sparse. Obviously you shouldn't exceed the fixed-size limit above, or the current resolution.
You could also try starting your application fullscreen, this only makes sense for some applications though.
Upvotes: 0
Reputation: 4057
This really isn't a Java question, but a user interface design question. An application I am currently developing needs at least 1024 by 768 to fit everything properly. But if it didn't need the space, then why make it start at that size? Why not let the user maximize the window if he wants to? A user interface should work on as many different display sizes as possible.
My policy is that the best window size is the smallest one that still lets the user do everything he needs to do with the program. Now back to Java: When creating a swing app, call pack() after placing all the components into the containers. If for some reason I feel that pack tightens things up too much, then I might add a little to the width or height right after a call to pack.
If you need to learn the dimensions of the display you are running on, use this:
Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension screensize = toolkit.getScreenSize();
With swing, you can also set the preferred size for components and this will affect how much size they take up after a call to pack().
Upvotes: 1
Reputation: 285450
In my experience it's usually best not to set preferred sizes but to use layout managers judiciously and to call pack()
on the top level window after adding all components, letting the components and the layout managers size themselves.
Upvotes: 3
Reputation: 30042
Big enough so all the components fit in the JFrame
and no bigger. Typically, I do not set the frame size in pixels, and just let the components size the frame so I know everything will fit.
I would say it's safe to assume more than 1024x768 resolution, but it depends on how compatible your application needs to be. To be certain you can get the screen size with Toolkit.getDefaultToolkit().getScreenSize();
Upvotes: 0