FORTUNE

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

          SWT Layout - RowLayout

          Posted on 2006-03-08 19:01 fortune 閱讀(981) 評論(0)  編輯  收藏 所屬分類: 我的學習筆記
          RowLayout要比FillLayout使用多些,每個widget的長度和寬度都可以通過方法setLayout()設定widget的RowData。

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

          Wrap域
          指定該行或列空間不足放下當前控件時是否自動換行;default:true

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

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

          MarginLeft, MarginTop, MarginRight, MarginBottom and Spacing

          前面4個是指定于邊框距離的,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對象來改變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

          主站蜘蛛池模板: 通江县| 保靖县| 赤水市| 旬邑县| 乡城县| 呼图壁县| 黄石市| 麟游县| 平乡县| 中江县| 广南县| 昆明市| 托克逊县| 阳原县| 安庆市| 抚顺县| 如皋市| 黑山县| 临潭县| 新宁县| 海安县| 紫阳县| 湘乡市| 南昌市| 中卫市| 合川市| 黄浦区| 阿拉尔市| 合水县| 凤冈县| 巴林左旗| 开鲁县| 盐亭县| 霍城县| 哈尔滨市| 登封市| 乐昌市| 云龙县| 三台县| 南充市| 峨眉山市|