Question

Which Swing layout(s) do you recommend?

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.

 45  50339  45
1 Jan 1970

Solution

 67

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.

2009-12-02

Solution

 23

All of them, in combination. That's the whole point. Each layout manager fulfills different requirements, and by nesting panels with different layout managers, you can achieve almost anything.

The "do everything in a single panel" layout managers like GridBagLayout and GroupLayout (and lots of 3rd party ones) have their place, mainly when you need components in different parts of the layout to align, but with a large layout, they generally result in a huge, hard-to-handle mess.

2009-12-03