Using Layout Data Objects to control layout : Layout Basics « SWT « Java Tutorial






Using Layout Data Objects to control layout
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class LayoutDataControlLayout {
  public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);

    shell.setLayout(new GridLayout()); // Only with GridLayout you can use GridData
    Text text = new Text(shell, SWT.SINGLE|SWT.BORDER);
    text.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL));
    
    shell.setSize(450, 100);
    shell.open();

    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    display.dispose();
  }
}

The methods in the Control class to get and set layout data are:

public Object getLayoutData()
    public void setLayoutData(Object layoutData)








17.93.Layout Basics
17.93.1.Layouts
17.93.2.A few terms that are used frequently when discussing layouts
17.93.3.Setting Layouts
17.93.4.Using Layout Data Objects to control layoutUsing Layout Data Objects to control layout
17.93.5.Laying Out Children of a CompositeLaying Out Children of a Composite
17.93.6.Layout term: bounds, client areaLayout term: bounds, client area