3. custom Layout
Eclipse form provides two new la s
(1) tablewraplayout
· Problem: if the text above is set to long enough
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, because the layout of the body content is gridlayout.
· Eclipse form provides alternative layout tablewraplayout: similar to gridlayout, but it has the same automatic wrap function as HTML tables.
· The following is an example of 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 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 );
}
· The following shows the program changes:
1) tablewraplayout replaces gridlayout
2) use tablewrapdata to provide layout data information
3) The set attributes use attributes such as colspan and rowspan from HTML table cells.
· Note: you need to set the automatic wrap control to the SWT. Wrap style.
(2) columnlayout
· Columnlayout is another custom layout provided by ECLIPSE form.
· The layout of columnlayout is from top to bottom, from left to right
· When the width of the form is changed, the number of control columns is automatically adjusted to adapt to the width of the form.
· Columnlayout is easy to set. Generally, you only need to set the range of columns (the default value is 1-3)
· The following examples are provided in the relevant sections.
Article from: good love Learning Network (http://www.haoxiai.net) Web site: http://www.haoxiai.net/bianchengyuyan/jspjiaocheng/59014.html