Mega Code Archive

 
Categories / Java Tutorial / SWT
 

Define the margins and 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 MarginSpaceProperties {   public static void main(String[] args) {     Display display = new Display();     final Shell shell = new Shell(display);     FillLayout fillLayout = new FillLayout(SWT.HORIZONTAL);     // Width of horizontal margins placed along the left and right edges         fillLayout.marginWidth = 5;     // Height of vertical margins placed along the top and bottom edges     fillLayout.marginHeight = 5;          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();   } }