Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which Swing layout(s) do you recommend? [closed]

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.

like image 719
Carl Smotricz Avatar asked Dec 02 '09 11:12

Carl Smotricz


People also ask

What are the different layouts in swing?

The borderlayout arranges the components to fit in the five regions: east, west, north, south, and center. The CardLayout object treats each component in the container as a card. Only one card is visible at a time. The FlowLayout is the default layout.

Which layout manager is better if you want to view one frame at a time?

Answer 1: d. BorderLayout and GridLayout easily deal with this situation.

What is the default layout for JFrame?

BorderLayout is the default layout for the window objects such as JFrame, JWindow, JDialog, JInternalFrame etc. BorderLayout arranges the components in the five regions.


1 Answers

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.

like image 180
Joonas Pulakka Avatar answered Oct 17 '22 06:10

Joonas Pulakka