Layout managers and containers
Layout managers are objects that control the size and position of components within a container.
Some Java beans allow relationships between themselves. For example, the class java.awt.Container allows instances of java.awt.Component to be added to it as part of its components relationship. An example of java.awt.Container is a panel or a frame. An example of java.awt.Component is a button or a text box. In the visual editor for Java, containment relationships are shown in the Java Beans view and in the Design view.
A layout manager is an object that controls the size and position of components within a container. You can set the layout manager on a container to null and allow each component to size and position itself. However, the position of the GUI components will not correspond to the changes you make when you resize the window. Rather than having a fixed size and position for each component, the container will delegate the sizing and positioning of its components by using a layout manager.
Each layout manager has its own rules for distributing the components, but most layout managers place each component so that it is at least as big as its preferred size. The preferred size of components with user visible strings, such as button or label, is calculated dynamically. So, as the string length changes due to different locales or fonts, the layout manager will reposition each component. As the window is resized by a user at run time, the layout manager also repositions each component to optimize the new overall size. This makes layout managers invaluable for building user interfaces that will be deployed in an environment where label strings, fonts, or window size may vary.
Swing and Abstract Windows Toolkit (AWT) containers use the same set of layout managers, which are mostly AWT objects. Standard Widget Toolkit (SWT) containers use their own SWT layout managers.
Note: If you use a layout manager not supplied in the visual editor, the Design view will still construct the container correctly and render the components. However, you will not be able to update constraints using the Properties view or Design view.
Parent topic
Laying out components using the visual editor
Related concepts
Swing and AWT layout managers
SWT layout managers
Related tasks
Specifying a layout manager