Design
3. Custom layout
The Eclipse form provides 2 new layouts
(1) Tablewraplayout
• Problem: If the hyperlink text in the previous example is set to long enough
Link.settext ("This is a example of a form", very much longer and would need to wrap. ");
Even if Swt.wrap is set, the text content is not automatically WRAP because the layout of the body content is GridLayout
· The Eclipse form provides an alternative layout tablewraplayout: similar to GridLayout, but with an automatic wrap function like an HTML table
• The following is an example of an automatic wrap for hyperlink text:
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 a example of a form", very much longer and would 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);
}
• Here's where the program changes:
1) tablewraplayout substitution GridLayout
2 use Tablewrapdata to provide layout data information
3 Set properties using colspan, rowspan, etc. from HTML table cells
• Note that controls that need to be automatically wrap need to be set to Swt.wrap style
(2) Columnlayout
· Columnlayout is another custom layout provided by the Eclipse form
· Columnlayout is arranged from top to bottom, left to right
• Automatically adjusts the number of control columns to fit the form's width when changing the width of the form
· Columnlayout settings are simple, usually by setting the range of columns (default is 1-3)
In the later part of the relevant section will give examples of use