Mega Code Archive

 
Categories / Java Tutorial / SWT
 

Set spacing properties

The default (initial) value of each property is 0. 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();   } }