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

前端 未结 4 1813
佛祖请我去吃肉
佛祖请我去吃肉 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:28

    In a nutshell: because all the work that you explain above is done (or at least: should be done) by the layout manager.

    More often than not, when a null layout is used, it also implies that all positions and sizes are hardcoded to a single value, so no flexibility at all is given. This means that changes in window size, language, font size, display density or any other related parameter have no effect on the layout and you get the usual ugly effects: empty parts of the window; tiny, unresizable lists; buttons with their labels cut off; ...

    It sounds like the work you do should really be done by the Layout Manager. Either find one that does that (my personal suggestion would be MiGLayout, which does a lot and is easy to use) or write your own.

提交回复
热议问题