Using layouts for proper alignment of visible components

The Java language holds a powerful mechanism to properly align and size GUI elements within a frame with the Layout concept. Other than by stating absolute coordinates at design time of GUI elements, layouts define a display model relative to certain rules.

Examples in Class AboutBox

Class AboutBox of SimplyHTML is an example of how to apply the layout concept. GUI elements such as labels or images are placed onto panels. For each panel exactly one layout scheme is associated by which the panel controls positions and sizes of it's contents.

The panel textPane for instance uses a GridLayout with one column and six rows to arrange the labels contained in the panel one below the other with a gap of 5pt between each other. The contentPane of AboutBox uses a BorderLayout to align all other panels with a border of the contentPane. buttonPane sticks to the bottom edge of the contentPane, northPane to the top edge and so on.

Conclusion

By using layouts, the GUI elements are sized automatically to fit the resulting scheme. Most important, they all are resized according to the rules of respective layout when the container is resized. By defining layouts, the developer does not have to worry about how the components need to be sized and resized. Only their positions relative to each other and relative to their container need to be taken into account.

So the layout model rather follows the original intention of the developer rather than forcing him to transform the design intentions into coding models over and over again.