Open Java Project

          Keep it simple, Stupid, Less is more

          BlogJava 首頁 新隨筆 聯(lián)系 聚合 管理
            20 Posts :: 0 Stories :: 12 Comments :: 0 Trackbacks

          3、定制布局

          Eclipse Form提供了2個新的布局

          1TableWrapLayout

          l         問題:如果將上例中超鏈接的文本設置的足夠長

                        link.setText("This is an example of a form that is much longer and will need to wrap.");

          即使設置了SWT.WRAP,文本內(nèi)容不會自動WRAP,這是因為體內(nèi)容的布局是GridLayout

          l         Eclipse Form提供替代的布局TableWrapLayout:類似于GridLayout,但是具有象HTML表格一樣自動WRAP功能

          l         下面是解決超鏈接文本自動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         下面是程序變化的地方:

          n         TableWrapLayout替代GridLayout

          n         使用TableWrapData來提供布局數(shù)據(jù)信息

          n         設置的屬性使用colspanrowspan等來源于HTML表格單元的屬性

          l         要注意的是:需要自動WRAP的控件,需要設置成SWT.WRAP風格

          2)ColumnLayout

          l         ColumnLayoutEclipse Form提供的另一個定制布局

          l         ColumnLayout的布局方式是從上到下,從左到右

          l         在變化Form的寬度時,會自動調(diào)整控件列數(shù)以適應Form的寬度

          l         ColumnLayout的設置很簡單,通常只要設置列數(shù)的范圍(缺省是1-3

          l         在后面的相關部分會給出使用的例子

          posted on 2005-04-02 23:54 nelson_tu 閱讀(2181) 評論(0)  編輯  收藏 所屬分類: Eclipse開發(fā)
          主站蜘蛛池模板: 抚顺市| 万安县| 衡阳市| 吕梁市| 凤冈县| 抚松县| 肃北| 九龙县| 河间市| 阳泉市| 寻乌县| 九台市| 丰镇市| 沙雅县| 九寨沟县| 紫金县| 乐安县| 子洲县| 辰溪县| 五大连池市| 贵溪市| 古交市| 会泽县| 星座| 广饶县| 石河子市| 瓦房店市| 台前县| 钦州市| 图片| 长子县| 青田县| 芜湖市| 绥芬河市| 建阳市| 金乡县| 来宾市| 遵义市| 吴川市| 宜昌市| 合肥市|