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 閱讀(988) 評論(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

          主站蜘蛛池模板: 泰州市| 玉门市| 青龙| 新昌县| 仙居县| 天祝| 宁乡县| 沙雅县| 五台县| 富民县| 辽源市| 莲花县| 台山市| 北流市| 工布江达县| 姜堰市| 莆田市| 双鸭山市| 宜兰县| 尼木县| 萨嘎县| 昌乐县| 塘沽区| 梓潼县| 福泉市| 乐平市| 山阳县| 克山县| 彩票| 蒙阴县| 佛教| 信丰县| 罗山县| 临安市| 安龙县| 彝良县| 西贡区| 历史| 永靖县| 宽甸| 广南县|