Why null layouts and absolute positions are bad practice in Swing?

There are multiple problems with absolute positioning:

  • Different screen sizes and resolutions, what looks great on your machine would come out differently on another screen with a different resolution.
  • In the same vein, what happens when a user resizes the screen because they want to run your application side by side with some other application (to copy paste or whatever)
  • Different locales and font sizes, what happens to your labels when you use another locale, or another font, or change the font size.

There’s probably more reasons, but using a layout manager makes sure that content is redistributed when windows are resized, or when content of a container changes, …

Using absolute positioning is probably the easiest way in the beginning, but it pays to get to know the different layout managers and how they operate. It will save you from a lot of headaches due to, for example, changing requirements.

Leave a Comment