The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

What layout to use for a desktop application?

Hi, good day, would just like to ask if what do you usually use as a layout for creating desktop applications... i tried the default grid layout for a while but i found it very limitting in terms of positioning components and sizes.. so i've shifted to using a null layout and just assigning the x y coordinates and the size... but the code is really messy this way but it works.. what do people usually use.. iv seen a combination of layouts combined together with jpanels grouping each part of the interface... i was hoping to find a better way as i write desktop applications fairly frequently and was hoping use a more organized version than a null layout (setlayout(null))... i'm looking forward to make applications with nice designs too mostly like the mobile apps with flat ui designs and would also like to ask what would be the best direction to designing layouts with graphics buttons, animations on moise overs, animated backgrounds, maybe background music, pretty much graphic intensive but very streamlined look... thank u...

Re: What layout to use for a desktop application?

You usually use a multitude of layouts and several panels all of which can have different layouts again.

The most common is probably the BorderLayout because it is kind of a standard for most GUI's nowadays. The most flexible I would say is the MigLayout. Its (rather) easy to use and the results almost always look acceptable.
It is strongly discouraged to use a null layout. Its always a sign of bad design and never translates well with dynamic resizing of the window.

Re: What layout to use for a desktop application?

The desktop structure contains a permanent app bar with a floating action button. The app bar absorbs elements from the tablet and mobile bottom bars. Where possible, the window controls are absorbed into the app bar.

Side navigation menus can take up the full height of the screen size (including under the app bar) and be accessed temporarily or pinned for permanent display. Side nav menus, as well as the content canvas, can have their own secondary toolbars for tabs, palettes, or secondary actions.

Re: What layout to use for a desktop application?

In my 12 years of professional Swing GUI development, I've been able to get the layout I want 99% of the time just using GridBagLayout and a well-designed nesting of sub panels. Definitely try to avoid absolute positioning. It's almost always best to work with the layout managers instead of against them, even though it's strange and frustrating at first.