Package edu. methane;
Import org. Eclipse. SWT. Widgets .*;
Import org. Eclipse. SWT. layout .*;
Import org. Eclipse. SWT. SWT;
Public class sample4_17 ...{
Public static void main (string [] ARGs )...{
Display display = New Display ();
Shell shell = new shell (Display );
Shell. settext ("formlayout example ");
Formlayout = new formlayout (); // create a table layout object
Shell. setlayout (formlayout );
Label Label = new label (shell, SWT. Border); // create a label object in Shell
Label. settext ("label one ");
Formdata DATA = new formdata ();
Data. Top = new formattachment (0, 5); // the label is 5 pixels apart from the shell border.
Data. Left = new formattachment (0, 5); // the label and shell left border are 5 pixels apart.
Data. Bottom = new formattachment (50,-5); // the label is 5 pixels above the shell horizontal midline
Data. Right = new formattachment (50,-5); // the label is 5 pixels on the left of the shell vertical midline.
Label. setlayoutdata (data );
Composite composite = new composite (shell, SWT. None); // create a panel
Gridlayout = new gridlayout (); // create a grid layout object
Gridlayout. marginheight = 0;
Gridlayout. marginwidth = 0;
Composite. setlayout (gridlayout); // you can specify grid layout as the panel layout.
Button b1 = new button (composite, SWT. Push); // create button B1 on Composite
B1.settext ("B1 ");
Griddata = new griddata (griddata. fill_both); // sets the layout mode to bidirectional filling.
B1.setlayoutdata (griddata );
Button b2 = new button (composite, SWT. Push); // B2 sets the same as B1
B2.settext ("B2 ");
Griddata = new griddata (griddata. fill_both );
B2.setlayoutdata (griddata );
Button B3 = new button (composite, SWT. Push); // B2 sets the same as B1
B3.settext ("B3 ");
Griddata = new griddata (griddata. fill_both );
Use the "pdffacloud" trial version in the PDF file to create www.fineprint.cn
B3.setlayoutdata (griddata );
Data = new formdata (); // create a formdata object
Data. Top = new formattachment (0, 5); // set the composite to 5 pixels from the shell upper border
Data. Left = new formattachment (Label, 5); // set the composite to 5 pixels from the label.
Data. Bottom = new formattachment (50,-5); // set the composite to 5 pixels above the shell horizontal midline
Data. Right = new formattachment (100,-5); // set the composite to 5 pixels on the left of the shell right border
Composite. setlayoutdata (data); // sets the layout data of composite.
Text text = new text (shell, SWT. Border); // create a Text object
Text. settext ("text ");
Data = new formdata (); // create table layout data
Data. Top = new formattachment (Label, 5); // 5 pixels above the text
Data. Left = new formattachment (0, 5); // The left side of text is 5 pixels away from the shell's left border.
Data. Bottom = new formattachment (100,-5); // The Bottom Frame of text is 5 pixels away from the Bottom Frame of shell.
Data. Right = new formattachment (100,-5); // The Right Border of text is 5 pixels away from the right border of Shell
Text. setlayoutdata (data); // sets the layout data of text.
Shell. Pack ();
Shell. open ();
While (! Shell. isdisposed ())...{
If (! Display. readanddispatch ())...{
Display. Sleep ();
}
}
Display. Dispose ();
}
}