Why is it frowned upon to use a null layout in Swing?

If you layer the layout managers correctly the screen will re-flow to different sizes for you, the idea is to use a single set of layout managers on ALL screen sizes.

If you use null you will have to do each screen size yourself. Not only that but if the app can be windowed you have to support every possible size they might scroll to.

That’s kind of difficult to do, but the layout mangers are designed to do just that.

There are some common tricks. BorderLayout is a great layout to start with. Sometimes you might use it at multiple levels–often with just 2 or 3 components in it. That’s because it’s really good at giving all but one area the minimum required area and giving everything else to the CENTER.

FlowLayout can be useful but it’s tricky if your components are different sizes.

I wouldn’t try GridBagLayout unless you are planning to write code to feed your layout manager (an excellent solution at that!).

I also wouldn’t use GUI builders, they don’t know the overall way you want to reflow your layout.

Leave a Comment