3, custom layout
Eclipse Form provides 2 new layouts
(1) TableWrapLayout
l Q Q problem: If you set a sufficiently linked text setting in the previous example
Link.Settext ("This Is An Example of A Form That Is Much Longer and Will Need To Wrap.");
Even if SWT.WRAP is set, the text content will not automatically Wrap, this is because the layout of the body is GridLayout
l Eclipse Form provides an alternative layout TableWrapLayout: similar to GridLayout, but automatic WRAP function like an HTML form
l The following is an example of solving hyperlink text automatic Wrap:
Public void createpartControl (Composite Parent) {
Toolkit = new formtoolkit (parent.getdisplay ());
Form = Toolkit.createscrolledform (PARENT);
Form.Settext ("Hello, Eclipse Forms");
Composite body = form.getBody ();
TableWrapLayout Layout = New TableWraplayout ();
Body.setLayout (layout);
HyperLink Link = Toolkit.createHyperLink (Body, "Click Here.", SWT.WRAP);
Link.addhyperLinkListener (New HyperLinkAdapter () {
Public void linkactivated (Hyperlinkevent E) {
System.out.println ("Link ActiVated!");
}
});
Layout.numcolumns = 2;
Link.Settext ("This Is An Example of A Form That Is Much Longer and Will Need To Wrap.");
TableWrapData TD = New TableWrapData ();
Td.colspan = 2;
Link.setLayOutdata (TD);
Label label = Toolkit.createLabel (Body, "Text Field Label:");
Text text = Toolkit.createText (body, "");
TD = New TableWrapData (TableWrapData.Fill_GRAB);
Text.setLayOutdata (TD);
Text.SetData (formtoolkit.key_draw_border, formtoolkit.text_border);
Button button = Toolkit.createButton (body,
"An Example of a Checkbox in A Form", SWT.CHECK);
TD = New TableWrapData ();
Td.colspan = 2;
Button.setLayOutdata (TD);
Toolkit.PaintBordersFor (Body);
}
l The following is where the program changes:
n TableWraplayout replaces GridLayout
n Use TableWrapData to provide the properties of the layout data information n set by colspan, rowspan, etc. from the HTML table unit.
l Be careful: you need to automatically write control, you need to set it to SWT.WRAP style
(2) ColumnLayout
l ColumnLayout is another custom layout provided by Eclipse Form
l ColumnLayout layout is from top to bottom, from left to right
l When changing the width of the Form, the number of control columns will be automatically adjusted to accommodate the width of the Form.
l ColumnLayout is very simple, usually as long as the range of column number is set (the default is 1-3)
l The examples will be given in the relevant part of the following