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. The SWT class org.eclipse.swt.widgets.Composite allows instances of org.eclipse.swt.widgets.Control to be added as part of its controls relationship. In the visual editor for Java, containment relationships are shown in the Java Beans view and in the Design view. In other words, containers can contain components or other containers.
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, in a null layout the position of the GUI components will not react to a window being resized. With a layout manager, rather than having a fixed size and position for each component, the container's layout manager delegates the sizing and positioning of its components.
The layout property can be set for containers in the Properties view:
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 (due to localization, for example).
Swing and Abstract Windows Toolkit (AWT) containers use the same set of layout managers, which are mostly AWT objects. Standard Widget Toolkit (SWT) composites use their own SWT layout managers.