package edu.ch4;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示例");FormLayout formlayout = new FormLayout(); //创建表格布局对象shell.setLayout(formlayout);Label label=new Label(shell,SWT.BORDER); //在shell中创建Label对象label.setText("Label One");FormData data = new FormData();data.top = new FormAttachment(0, 5); //Label与shell上边框相距5象素data.left = new FormAttachment(0, 5); // Label与shell左边框相距5象素data.bottom = new FormAttachment(50, -5);//Label在shell水平中线上方5象素data.right = new FormAttachment(50, -5); // Label在shell垂直中线左边5象素label.setLayoutData(data);Composite composite = new Composite(shell, SWT.NONE);//创建面板GridLayout gridLayout = new GridLayout(); //创建网格布局对象gridLayout.marginHeight = 0;gridLayout.marginWidth = 0;composite.setLayout(gridLayout); //设置面板布局方式为网格布局Button b1 = new Button(composite, SWT.PUSH); //在composite上创建button B1b1.setText("B1");GridData gridData = new GridData(GridData.FILL_BOTH); //设置布局方式为双向填充b1.setLayoutData(gridData);Button b2 = new Button(composite, SWT.PUSH); //B2设置同B1b2.setText("B2");gridData = new GridData(GridData.FILL_BOTH);b2.setLayoutData(gridData);Button b3 = new Button(composite, SWT.PUSH); //B2设置同B1b3.setText("B3");gridData = new GridData(GridData.FILL_BOTH);PDF 文件使用 "pdfFactory" 试用版本创建 www.fineprint.cnb3.setLayoutData(gridData);data = new FormData(); //创建FormData对象data.top = new FormAttachment(0, 5); //设置composite距shell上边框5象素data.left = new FormAttachment(label, 5);//设置composite距label 5象素data.bottom = new FormAttachment(50, -5);//设置composite在shell水平中线上方5象素data.right = new FormAttachment(100, -5);//设置composite在shell右边框的左侧5象素composite.setLayoutData(data); //设置composite的布局数据Text text=new Text(shell,SWT.BORDER); //创建Text对象text.setText("Text");data = new FormData(); //创建表格布局数据data.top = new FormAttachment(label, 5); //text上方离label 5象素data.left = new FormAttachment(0, 5); // text左边离shell左边框5象素data.bottom = new FormAttachment(100, -5); // text下边框离shell下边框5象素data.right = new FormAttachment(100, -5); // text右边框离shell右边框5象素text.setLayoutData(data); //设置text的布局数据shell.pack();shell.open();while (!shell.isDisposed()) ...{if (!display.readAndDispatch()) ...{display.sleep();}}display.dispose();}}