·首先获得Form的体内容它是一个Composite对象
·设置其布局为GridLayout
·通过FormToolkit创建一个超链接(Hyperlink)控件
·添加超链接事件侦听器响应超链接的点击
()添加通用控件
·由于Form的体内容是一个Composite对象所以允许在其中创建SWT控件
·但是SWT控件是被设计为适合窗口对话框的所以在Form中使用是有问题的
·在Form中使用FormToolkit创建对应的通用控件
public void createPartControl(Composite parent) {
toolkit = new FormToolkit(parentgetDisplay());
form = toolkitcreateScrolledForm(parent);
formsetText(Hello Eclipse Forms);
Composite body = formgetBody();
GridLayout layout = new GridLayout();
bodysetLayout(layout);
Hyperlink link = toolkitcreateHyperlink(body Click hereSWTWRAP);
linkaddHyperlinkListener(new HyperlinkAdapter() {
public void linkActivated(HyperlinkEvent e) {
Systemoutprintln(Link activated!);
}
});
layoutnumColumns = ;
GridData gd = new GridData();
gdhorizontalSpan = ;
linksetLayoutData(gd);
Label label = toolkitcreateLabel(body Text field label:);
Text text = toolkitcreateText(body );
textsetLayoutData(new GridData(GridDataFILL_HORIZONTAL));
textsetData(FormToolkitKEY_DRAW_BORDER FormToolkitTEXT_BORDER);
Button button = toolkitcreateButton(bodyAn example of a checkbox in a form SWTCHECK);
gd = new GridData();
gdhorizontalSpan = ;
buttonsetLayoutData(gd);
toolkitpaintBordersFor(body);
}
·上面的例子添加了三个通用控件LabelText和CheckBox
·由于缺省创建的Text控件的外观是D的而要达到象PDE一样的FLAT外观需要做些额外工作
) 调用setData()方法添加重画边框的附加信息
) 调用FormToolkit的paintBordersFor()方法重画FLAT外观的边框
[] [] []