Set spacing properties : FillLayout « SWT « Java Tutorial






The default (initial) value of each property is 0.

Set spacing properties
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

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

    FillLayout fillLayout = new FillLayout(SWT.HORIZONTAL);
    
    fillLayout.marginWidth = 5;
    fillLayout.marginHeight = 5;
    
    // Number of pixels between the edge of a cell and edges of its neighboring cells
    fillLayout.spacing = 10;    
    
    shell.setLayout(fillLayout);
    
    Button button1 = new Button(shell, SWT.PUSH);
    button1.setText("button1");

    Button button2 = new Button(shell, SWT.PUSH);
    button2.setText("button number 2");

    Button button3 = new Button(shell, SWT.PUSH);
    button3.setText("3");
    
    shell.setSize(450, 100);
    shell.open();

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








17.95.FillLayout
17.95.1.Using FillLayout
17.95.2.Configure the layout orientation: HORIZONTAL and VERTICALConfigure the layout orientation: HORIZONTAL and VERTICAL
17.95.3.Define the margins and spacing propertiesDefine the margins and spacing properties
17.95.4.Set spacing propertiesSet spacing properties