FORTUNE

          THE WAY TO THE MASTER...
          posts - 49, comments - 18, trackbacks - 0, articles - 1
            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          SWT Layout - RowLayout

          Posted on 2006-03-08 19:01 fortune 閱讀(980) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): 我的學(xué)習(xí)筆記
          RowLayout要比FillLayout使用多些,每個(gè)widget的長(zhǎng)度和寬度都可以通過(guò)方法setLayout()設(shè)定widget的RowData。

          Type域
          指定按行或列排列  如: new RowLayout(SWT.HORIZONTAL);default:horizontal

          Wrap域
          指定該行或列空間不足放下當(dāng)前控件時(shí)是否自動(dòng)換行;default:true

          Pack域
          指定Layout中的widgets是否采用它們的自然大小,如果pack為false則所有widget強(qiáng)制為相同大小default:true

          Justify域
          true表明Layout中的所有widgets每行都從左到右平均距離展開(kāi)default:false

          MarginLeft, MarginTop, MarginRight, MarginBottom and Spacing

          前面4個(gè)是指定于邊框距離的,spacing指定widget之間的間隔

             RowLayout rowLayout = new RowLayout();

             rowLayout.wrap = false;

             rowLayout.pack = false;

             rowLayout.justify = true;

             rowLayout.type = SWT.VERTICAL;

             rowLayout.marginLeft = 5;

             rowLayout.marginTop = 5;

             rowLayout.marginRight = 5;

             rowLayout.marginBottom = 5;

             rowLayout.spacing = 0;

             shell.setLayout(rowLayout)

           

          下面的代碼使用RowData對(duì)象來(lái)改變button的大小

          import org.eclipse.swt.*;

          import org.eclipse.swt.widgets.*;

          import org.eclipse.swt.layout.*;

           

          public class RowDataExample {

           

             public static void main(String[] args) {

                 Display display = new Display();

                 Shell shell = new Shell(display);

                 shell.setLayout(new RowLayout());

                 Button button1 = new Button(shell, SWT.PUSH);

                 button1.setText("Button 1");

                 button1.setLayoutData(new RowData(50, 40));

                 Button button2 = new Button(shell, SWT.PUSH);

                 button2.setText("Button 2");

                 button2.setLayoutData(new RowData(50, 30));

                 Button button3 = new Button(shell, SWT.PUSH);

                 button3.setText("Button 3");

                 button3.setLayoutData(new RowData(50, 20));

                 shell.pack();

                 shell.open();

                 while (!shell.isDisposed()) {

                    if (!display.readAndDispatch()) display.sleep();

                 }

             }

          }

           

          參考:http://www.eclipse.org/articles/Understanding%20Layouts/Understanding%20Layouts.htm

          主站蜘蛛池模板: 灵丘县| 潮州市| 玛沁县| 山西省| 保德县| 麟游县| 金坛市| 凤山县| 外汇| 淄博市| 额敏县| 长子县| 英超| 清徐县| 金平| 巴青县| 千阳县| 叙永县| 景洪市| 湘阴县| 浦东新区| 甘南县| 城固县| 定日县| 吴旗县| 三门峡市| 介休市| 静宁县| 大洼县| 个旧市| 盐山县| 赣州市| 雷山县| 武乡县| 建阳市| 镇平县| 剑川县| 丘北县| 安康市| 尼勒克县| 奉贤区|