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

前端 未结 4 1796
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-21 04:44

Recently, I started creating a program for the company I work for. Just as background info, I\'m still a student and a beginner programmer, so my solution is probably not re

4条回答
  •  梦谈多话
    2020-11-21 05:23

    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.

提交回复
热议问题