Standard Layouts in SWT Library
Added 31 Jul 2008
The standard layout classes in the SWT library are:
FillLayoutlays out equal-sized widgets in a single row or columnRowLayoutlays out widgets in a row or rows, with fill, wrap, and spacing optionsGridLayoutlays out widgets in a gridFormLayoutlays out widgets by creating attachments for each of their sides
To use the standard layouts, you need to import the SWT layout package:
import org.eclipse.swt.layout.*;
Layouts are pluggable. To set a Composite widget's
layout, you use the widget's setLayout(Layout) method. In
the following code, a Shell (a subclass of Composite)
is told to position its children using a RowLayout:
Shell shell = new Shell();
shell.setLayout(new RowLayout());
A layout class may have a corresponding layout data class: a
subclass of Object that contains layout data for a specific
child. By convention, layout data classes are identified by substituting
"Data" for "Layout" in the class name. For example,
the standard layout class RowLayout has a layout data class
called RowData, the layout class GridLayout
uses a layout data class called GridData, and the layout
class FormLayout has a layout data class called FormData.
A widget's layout data class is set as follows:
Button button = new Button(shell, SWT.PUSH);
button.setLayoutData(new RowData(50, 40));