Form control
Form is a basic control used to host UI Forms. It provides for setting
a title and scrolling the content similar to a Web browser. What makes forms
appealing is the fact that the content is an SWT composite that can be used as
you would use it in other contexts. For example, consider the following code
snippet:
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 Forms manipulate SWT widgets in a number of ways in order to achieve the
desired effect. For that reason, controls are typically created using the
FormToolkit
. Normally an instance of a ScrolledForm
is
created in order to get scrolling. When forms need to be nested, a Form
instance provides everything except for scrolling of the form content.
Form content is rendered below the title. SWT widgets are created in the form
using Form.getBody()
as a parent.