// Create a formlayout object
Formlayout = new formlayout ();
Formlayout. marginheight = 5; // you can set up or down to 5 pixels.
Formlayout. marginwidth = 5; // set the Left and Right padding to 5 pixels.
Shell. setlayout (formlayout );
Button Bt1 = new button (shell, SWT. Push );
Bt1.settext ("B1 ");
// Create a formdata object
Formdata = new formdata ();
// Set the position of the upper border of the control
Formdata. Top = new formattachment (30, 70, 60 );
// Set the position of the lower border of the control
Formdata. Bottom = new formattachment (100,-5 );
// Set the position of the Left Border
Formdata. Left = new formattachment (20, 0 );
// Set the position of the Right Border
// Formattachment (INT numerator, int offset)
// Numerator indicates the number of molecules. The default denominator value is 100,
// Offset is the offset, positive offset, and negative offset.
Formdata. Right = new formattachment (100,-3 );
Bt1.setlayoutdata (formdata );
Button bt3 = new button (shell, SWT. Push );
Bt1.settext ("button 1 ");
Formdata formdata1 = new formdata ();
// Set the position of the upper border
Formdata1.top = new formattachment (20, 0 );
// Set the position of the Left Border
Formdata1.left = new formattachment (20,-10 );
Bt3.setlayoutdata (formdata1 );
Button bt4 = new button (shell, SWT. Push );
Formdata1 = new formdata ();
// Set the position of the ending border J.
Formdata1.top = new formattachment (20, 0 );
// 20 pixels to the right of bt3
Formdata1.left = new formattachment (bt3, 20, SWT. Right );
Bt4.setlayoutdata (formdata1 );
Bt4.settext ("wide button 2 ");
Shell. open ();