Which Swing layout(s) do you recommend?

Carl Smotricz picture Carl Smotricz · Dec 2, 2009 · Viewed 43k times · Source

There are 8 layout managers in the Java library alone, and then there's a bunch of 3rd party products as well.

The other day, I tried to use SpringLayout and... well, it ain't working out for me. See my other question. So... if you have a Swing app to design, and you want your layout just so, what are your preferred layout managers? Any interesting/useful experiences to relate?

Update: Yup, sure I'm aware that different LMs are appropriate for different layouts. But I'd expect that most of you use 1, 2 or maybe 3 for most everything you do, or you swear by a single one that's so versatile you never need anything else. With enough responses, I'd expect to see something like a bell curve, with a peak on GridBagLayout or MigLayout (for example) and a long tail of a few stragglers using (say) BoxLayout or FlowLayout.

Hopefully, the distribution of responses will reveal some trends as to what people use most to Get Stuff Done


UPDATE and Summary

OK, after almost 2 days, MiGLayout is definitely out in front! Its fans will be happy to hear that it looks like this layout will be entering the "official" library soon.

GroupLayout, FormsLayout and TableLayout are relatively new and haven't gotten much exposure. Perhaps others will be as surprised to find out about them as I was.

Answer

Joonas Pulakka picture Joonas Pulakka · Dec 2, 2009

MiGLayout, no doubt. Honestly, it's the only Swing layout manager I know of that makes any sense.

The mere fact that there are 8 layout managers in the core JDK is a good sign that the Swing creators had absolutely no idea about what they were trying to do. This is not to trash the rest of the Swing - it's a good GUI toolkit, except for the layout managers.