Using RowLayout : RowLayout « SWT « Java Tutorial

  1. places all controls in a single column or row.
  2. it doesn't force all contained controls to the same size.
  3. wrap controls to a new row or column if it runs out of space.
  4. uses the RowData class to determine initial widths and heights for its controls.
Using RowLayout
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class RowLayoutTest {
  public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    RowLayout layout = new RowLayout(SWT.VERTICAL);
    layout.marginLeft = 20;
    layout.marginTop = 20;
    layout.justify = true;
    new Button(shell, SWT.PUSH).setText("one");
    new Button(shell, SWT.PUSH).setText("two");
    new Button(shell, SWT.PUSH).setText("three");
    new Button(shell, SWT.PUSH).setText("four");
    new Button(shell, SWT.PUSH).setText("five");
    new Button(shell, SWT.PUSH).setText("six");
    Button b = new Button(shell, SWT.PUSH);
    b.setLayoutData(new RowData(100, 100));;
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {

17.99.1.Using RowLayoutUsing RowLayout
17.99.2.Using all default value from RowLayoutUsing all default value from RowLayout
17.99.3.RowLayout: align widgets in a rowRowLayout: align widgets in a row
17.99.4.RowLayout snippet: align widgets in a columnRowLayout snippet: align widgets in a column
17.99.5.RowLayout: fillRowLayout: fill
17.99.6.RowLayout: justifyRowLayout: justify
17.99.7.RowLayout: marginLeft, marginRight, marginTop, marginBottomRowLayout: marginLeft, marginRight, marginTop, marginBottom
17.99.8.pack: Specifies whether all controls should take their preferred sizepack: Specifies whether all controls should take their preferred size
17.99.9.RowLayout: spacingRowLayout: spacing
17.99.10.RowLayout: typeRowLayout: type
17.99.11.RowLayout: wrapRowLayout: wrap
17.99.12.Using RowData ObjectsUsing RowData Objects