表单是用来托管 UI 表单的基本控件。它支持设置标题以及以类似于 Web 浏览器的方式滚动内容。表单吸引人的地方在于内容是 SWT 组合体,您可以象在其它上下文中使用它那样使用它。例如,考虑以下代码段:
public class FormView extends ViewPart { private FormToolkit toolkit; private ScrolledForm form; /** * The constructor. */ public FormView() { } /** * This is a callback that will allow us to create the viewer and * initialize it. */ public void createPartControl(Composite parent) { toolkit = new FormToolkit(parent.getDisplay()); form = toolkit.createScrolledForm(parent); form.setText("Hello, Eclipse Forms"); } /** * Passing the focus request to the form. */ public void setFocus() { form.setFocus(); } /** * Disposes the toolkit */ public void dispose() { toolkit.dispose(); super.dispose(); } }
UI 表单采用许多方式处理 SWT 窗口小部件以便达到期望的效果。因此,通常使用 FormToolkit
来创建控件。通常,创建一个 ScrolledForm
实例以便能够进行滚动。当需要嵌套表单时,Form
实例提供了除滚动表单内容以外的所有功能。
表单内容显示在标题下方。SWT 窗口小部件是使用 Form.getBody()
作为父代在表单中创建的。