We’ve been using the null layout manager, in our previous examples of Java Swing. This is sometimes referenced as an absolute positioning layout, because we are required to control how the items are laid out and where. We do this with setBounds()
or another method which allows us to define both the size of the component as well as the position on the parent frame.
However, Java provides several other layout managers for us. Oracle, the owner of Java (They bought out Sun who created Java years ago) has a good visual representation of the layout managers. The layout managers will calculate, and recalculate if the window changes sizes, the positions and sizes of your elements.
Common layout managers include:
- BorderLayout
- BoxLayout
- CardLayout
- FlowLayout
- GridBagLayout
- GridLayout
- GroupLayout
- SpringLayout
Note however, that GroupLayout and SpringLayout are both designed to be used by GUI builders, not necessarily by a developer who is putting items into place. That is because of some of the complexities of how you might build them.
Complex Designs
The null layout might seem like the obvious choice therefore, however, it has limitations of what to do if the screen size needs to change, for one.
Instead, you might use panels with different layouts, to get the design you really want.
Intro to Layout Managers was originally found on Access 2 Learn
One Comment
Comments are closed.