posts - 1,  comments - 25,  trackbacks - 0
          First , The nomal composite is very different from the Table Viewer and Tree Viewer.
          The Table viewer and Tree Viewer only need add the SWT.H_SCROLL and SWT.V_SCROLL into  the Constructor. The context will be move with scroll bar.
          This is because the viewer has been include the scrollabled composite. 

          So . nomal composite should implment the scrollableComposte by ourself.

                  1. Set parent compsoite's layout as FillLayout.   

                 parentComposite.setLayout(new FillLayout());
                  ScrolledComposite scrolledComposite = new ScrolledComposite(parentComposite,  SWT.H_SCROLL|SWT.V_SCROLL);
                  
                   2. Create the main composite and use the scrolled Composite as it's father.
                  Composite mainComposite = new Composite(scrolledComposite,SWT.NONE);

                  3. Set scrolled composite can controll the main composite.
                  scrolledComposite.setContent(mainComposite);
                  mainComposite.setBackground(Display.getCurrent().getSystemColor (SWT.COLOR_WHITE));// White color
                  mainComposite.setLayout(new GridLayout(1,true));
                  GridData data = new GridData(GridData.FILL_BOTH);
                  mainComposite.setLayoutData(data);
                   
                 4. Set the other attributes.        
                  scrolledComposite.setExpandHorizontal(true);
                  scrolledComposite.setExpandVertical(true);
                  scrolledComposite.setMinWidth(800);
                  scrolledComposite.setMinHeight(400);


           總結:
           1)在為Composite添加滾動條時,最上面的Composite的布局需設為FillLayout();
           2) 不要直接往scrolledComposite上面添加控件;
           3) 在創建完ScrolledComposite后不要忘記使用setContent()方法去設置滾動條所控制的Composite;
           4) 最重要的是,Scrolledcomposite的以下四個參數必須設置才能出現滾動條:
              scrolledComposite.setExpandHorizontal(true);
              scrolledComposite.setExpandVertical(true);
              scrolledComposite.setMinWidth(800);
              scrolledComposite.setMinHeight(400);
              只有前兩項設為true之后,后面的兩項才起作用。
          5) 對于setMinWidth()和setMinHeight()方法,API的注釋中是說用來設置滾動條出現的最小寬度和高度,但是我試了一下,有時出現滾動條了,
              但是拖動滾動條還是不能顯示Composite里面的全部內容,于是把setMinWidth()和setMinHeight()設大一些就可以了,個人感覺滾動條出現的
              寬度和高度檢測Scrolledcomposite自己已經實現了,這里的寬度和高度是指拖動滾動條里可以看到的Composite的最大寬度和最大高度。

          posted on 2009-03-20 16:37 Daniel 閱讀(382) 評論(0)  編輯  收藏 所屬分類: SWT

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2025年8月>
          272829303112
          3456789
          10111213141516
          17181920212223
          24252627282930
          31123456

          常用鏈接

          留言簿(3)

          隨筆檔案

          文章分類

          文章檔案

          相冊

          搜索

          •  

          最新評論

          主站蜘蛛池模板: 东明县| 江华| 中卫市| 湖口县| 龙岩市| 丰顺县| 普陀区| 馆陶县| 湖口县| 九龙县| 工布江达县| 福州市| 天门市| 盐津县| 澄江县| 华坪县| 桂平市| 宁晋县| 尉犁县| 象州县| 海安县| 班戈县| 东方市| 济南市| 通辽市| 泸水县| 尉氏县| 墨竹工卡县| 马关县| 呼伦贝尔市| 泰宁县| 天水市| 辰溪县| 泽州县| 沈丘县| 开阳县| 晴隆县| 银川市| 和田市| 孟村| 天津市|