<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 28,  comments - 15,  trackbacks - 0

        本文綜合了GridLayout、GridData、Composite以及Tree、TreeItem構造了一個比較復雜的應用例子。

       /*---------- 構造代碼 ---------*/

    public class GridLayoutObject {
     
     public void buildLayout(){
      
      Display display = new Display();
      Shell shell = new Shell(display);
      
      GridLayout configLayout = new GridLayout();
      configLayout.marginHeight = 0;
      configLayout.marginWidth = 0;
      
      shell.setLayout(configLayout);
      
      GridData gridData;
      
      SashForm form = new SashForm(shell,SWT.HORIZONTAL);
      gridData = new GridData(GridData.FILL_BOTH);
      form.setLayoutData(gridData);
        
         Composite cLeftSide = new Composite(form, SWT.BORDER);
         gridData = new GridData(GridData.FILL_BOTH);
         cLeftSide.setLayoutData(gridData);
        
         FormLayout layout = new FormLayout();
         cLeftSide.setLayout(layout);
          
         Composite cFilterArea = new Composite(cLeftSide, SWT.NONE);
         cFilterArea.setLayout(new FormLayout());
          
         final Text txtFilter = new Text(cFilterArea, SWT.BORDER);
         txtFilter.setText("hi");
         txtFilter.selectAll();
         txtFilter.setFocus();
        
         Label lblX = new Label(cFilterArea, SWT.WRAP);
         lblX.setText("l1");
        
         Label lblSearch = new Label(cFilterArea, SWT.NONE);
         lblSearch.setText("l2");
        
         Tree tree = new Tree(cLeftSide, SWT.NONE);
         FontData[] fontData = tree.getFont().getFontData();
         fontData[0].setStyle(SWT.BOLD);
         Font filterFoundFont = new Font(display, fontData);
        
         FormData formData;

           formData = new FormData();
           /*注意:80,代表*/
           formData.bottom = new FormAttachment(100, -5);
           formData.left = new FormAttachment(0, 0);
           formData.right = new FormAttachment(100, 0);
           cFilterArea.setLayoutData(formData);
          
           formData = new FormData();
           formData.top = new FormAttachment(0,5);
           formData.left = new FormAttachment(0, 5);
           lblSearch.setLayoutData(formData);

           formData = new FormData();
           formData.top = new FormAttachment(0,5);
           formData.left = new FormAttachment(lblSearch,5);
           formData.right = new FormAttachment(lblX, -3);
           txtFilter.setLayoutData(formData);

           formData = new FormData();
           formData.top = new FormAttachment(0,5);
           formData.right = new FormAttachment(100,-5);
           lblX.setLayoutData(formData);

           formData = new FormData();
           formData.top = new FormAttachment(0, 0);
           formData.left = new FormAttachment(0,0);
           formData.right = new FormAttachment(100,0);
           formData.bottom = new FormAttachment(cFilterArea,-1);
           tree.setLayoutData(formData);
          
           Composite cRightSide = new Composite(form, SWT.NULL);
           configLayout = new GridLayout();
           configLayout.marginHeight = 3;
           configLayout.marginWidth = 0;
           cRightSide.setLayout(configLayout);
      
           // Header
           Composite cHeader = new Composite(cRightSide, SWT.BORDER);
           configLayout = new GridLayout();
           configLayout.marginHeight = 3;
           configLayout.marginWidth = 0;
           configLayout.numColumns = 2;
           configLayout.marginRight = 5;
           cHeader.setLayout(configLayout);
           gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
           cHeader.setLayoutData(gridData);
      
           cHeader.setBackground(display.getSystemColor(SWT.COLOR_LIST_SELECTION));
           cHeader.setForeground(display.getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT));
          
           Label lHeader = new Label(cHeader, SWT.NULL);
           lHeader.setBackground(display.getSystemColor(SWT.COLOR_LIST_SELECTION));
           lHeader.setForeground(display.getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT));
           fontData = lHeader.getFont().getFontData();
           fontData[0].setStyle(SWT.BOLD);
           int fontHeight = (int)(fontData[0].getHeight() * 1.2);
           fontData[0].setHeight(fontHeight);
           Font headerFont = new Font(display, fontData);
           lHeader.setFont(headerFont);
           gridData = new GridData(GridData.VERTICAL_ALIGN_CENTER | GridData.HORIZONTAL_ALIGN_BEGINNING);
           lHeader.setLayoutData(gridData);
          
           Label usermodeHint = new Label(cHeader, SWT.NULL);
           usermodeHint.setBackground(display.getSystemColor(SWT.COLOR_LIST_SELECTION));
           usermodeHint.setForeground(display.getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT));
           gridData = new GridData(GridData.VERTICAL_ALIGN_CENTER | GridData.HORIZONTAL_ALIGN_END | GridData.GRAB_HORIZONTAL);
           usermodeHint.setLayoutData(gridData);
          
           Composite cConfigSection = new Composite(cRightSide, SWT.NULL);
           StackLayout layoutConfigSection = new StackLayout();
           cConfigSection.setLayout(layoutConfigSection);
           gridData = new GridData(GridData.FILL_BOTH);
           gridData.horizontalIndent = 2;
           cConfigSection.setLayoutData(gridData);
      
      
           form.setWeights(new int[] {50,80});
          
           Listener scResizeListener = new Listener() {
        public void handleEvent(Event event) {
         setupSC((ScrolledComposite)event.widget);
        }
       };
           ScrolledComposite sc = new ScrolledComposite(cConfigSection, SWT.H_SCROLL | SWT.V_SCROLL);
             sc.setExpandHorizontal(true);
             sc.setExpandVertical(true);
             sc.setLayoutData(new GridData(GridData.FILL_BOTH));
            sc.getVerticalBar().setIncrement(16);
            sc.addListener(SWT.Resize, scResizeListener);
          
            ModelConfigSection a = new ModelConfigSection();
            Composite c = a.configSectionCreate(sc);
            sc.setContent(c);
           TreeItem item1 = new TreeItem(tree,SWT.NULL);
           item1.setText("說明");
           item1.setData("Panel", sc);
           layoutConfigSection.topControl = sc;
          
           ScrolledComposite sc1 = new ScrolledComposite(cConfigSection, SWT.H_SCROLL | SWT.V_SCROLL);
              sc1.setExpandHorizontal(true);
              sc1.setExpandVertical(true);
              sc1.setLayoutData(new GridData(GridData.FILL_BOTH));
             sc1.getVerticalBar().setIncrement(16);
             sc1.addListener(SWT.Resize, scResizeListener);
       
       
           
           TreeItem item2 = new TreeItem(tree,SWT.NULL);
           item2.setText("網絡配置");
           item2.setData("Panel",sc1);

           ScrolledComposite sc2 = new ScrolledComposite(cConfigSection, SWT.H_SCROLL | SWT.V_SCROLL);
              sc2.setExpandHorizontal(true);
              sc2.setExpandVertical(true);
              sc2.setLayoutData(new GridData(GridData.FILL_BOTH));
             sc2.getVerticalBar().setIncrement(16);
             sc2.addListener(SWT.Resize, scResizeListener);
            
           TreeItem item21 = new TreeItem(item2,SWT.NULL);
           item21.setText("路由配置");
           item21.setData("Panel", sc2);
          
          
           ScrolledComposite sc3 = new ScrolledComposite(cConfigSection, SWT.H_SCROLL | SWT.V_SCROLL);
              sc3.setExpandHorizontal(true);
              sc3.setExpandVertical(true);
              sc3.setLayoutData(new GridData(GridData.FILL_BOTH));
             sc3.getVerticalBar().setIncrement(16);
             sc3.addListener(SWT.Resize, scResizeListener);
           TreeItem item22 = new TreeItem(item2,SWT.NULL);
           item22.setText("網關配置");
             item22.setData("Panel", sc3);
          
           TreeItem[] items = { tree.getItems()[0] };
           tree.setSelection(items);
          
           shell.pack();
       shell.open();
       
       while(!shell.isDisposed()){
        if(!display.readAndDispatch()){
         display.sleep();
        }
       }
       
      display.dispose();
     }
     
     public void setupSC(ScrolledComposite sc) {
      Composite c = (Composite) sc.getContent();
      if (c != null) {
       Point size1 = c.computeSize(sc.getClientArea().width, SWT.DEFAULT);
       Point size = c.computeSize(SWT.DEFAULT, size1.y);
       sc.setMinSize(size);
      }
      sc.getVerticalBar().setPageIncrement(sc.getSize().y);
     }

    }

    /*----------    動作控制接口以及實現代碼 --------*/

    public interface ConfigSectionTest {
     public Composite configSectionCreate(final Composite parent);
    }

    public class ModelConfigSection implements ConfigSectionTest {

     public Composite configSectionCreate(Composite parent) {
      GridData gridData;
      GridLayout layout;
      
      final Composite cMode = new Composite(parent,SWT.WRAP);
      gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL|GridData.VERTICAL_ALIGN_FILL);
      cMode.setLayoutData(gridData);
      layout = new GridLayout();
      layout.numColumns =4;
      layout.marginHeight = 0;
      cMode.setLayout(layout);
      
      
      gridData = new GridData();
      gridData.horizontalSpan = 4;
      final Group gRadio = new Group(cMode, SWT.WRAP);
      gRadio.setText("用戶熟練程度");
      gRadio.setLayoutData(gridData);
      gRadio.setLayout(new RowLayout(SWT.HORIZONTAL));
      
      Button button0 = new Button (gRadio, SWT.RADIO);
      button0.setText("初級");
      
      Button button1 = new Button (gRadio, SWT.RADIO);
      button1.setText("中級");
      
      Button button2 = new Button (gRadio, SWT.RADIO);
      button2.setText("高級");
      
      button0.setSelection(true);
      
      gridData = new GridData(GridData.FILL_HORIZONTAL);
         final Label label = new Label(cMode, SWT.WRAP);
         gridData.horizontalSpan = 4;
         label.setLayoutData(gridData);
         label.setText("什么玩意!");
        
        
      return cMode;
     }

    }

    /*----------- 測試代碼 ----------------*/

    public class GridLayoutTest {
     
     public static void main(String[] args){
      
      GridLayoutObject obj = new GridLayoutObject();
      obj.buildLayout();
      
      
     }
    }


    運行結果:

    posted on 2009-08-13 17:27 zhangxl 閱讀(2501) 評論(0)  編輯  收藏 所屬分類: SWT、SWING、AWT

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


    網站導航:
     
    <2025年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    常用鏈接

    留言簿(1)

    隨筆分類(17)

    隨筆檔案(28)

    文章分類(30)

    文章檔案(30)

    相冊

    收藏夾(2)

    hibernate

    java基礎

    mysql

    xml

    關注

    壓力測試

    算法

    最新隨筆

    搜索

    •  

    積分與排名

    • 積分 - 96257
    • 排名 - 601

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 在线看片免费人成视频福利| 国产精品免费一区二区三区| 114一级毛片免费| 亚洲s色大片在线观看| 久久久久久精品成人免费图片 | 亚洲欧美日韩中文无线码| 国产成人yy免费视频| 91亚洲国产成人久久精品| 日韩亚洲国产高清免费视频| 456亚洲人成在线播放网站| 黄色成人网站免费无码av| 无码国产亚洲日韩国精品视频一区二区三区 | 大桥未久亚洲无av码在线| 国产一区二区三区在线免费观看 | 亚洲精品高清国产一线久久| 成人性做爰aaa片免费看| 亚洲av色福利天堂| 西西大胆无码视频免费| 亚洲欧洲无卡二区视頻| 亚洲第一成人影院| 久久99精品免费视频| 亚洲videosbestsex日本| 免费观看亚洲人成网站| 成人国产精品免费视频| 噜噜噜亚洲色成人网站∨ | 亚洲国产精品成人久久蜜臀| 三年片免费观看大全国语| 亚洲色av性色在线观无码| 四虎影院在线免费播放| 国产精品极品美女自在线观看免费| 久久久久亚洲AV无码专区首| 一二三四免费观看在线电影| 国产亚洲女在线线精品| 亚洲AV福利天堂一区二区三| 成人免费看吃奶视频网站| 久久九九久精品国产免费直播| 老司机亚洲精品影院无码| 日美韩电影免费看| 日韩精品无码免费专区午夜| 久久精品国产99国产精品亚洲| 亚洲第一视频在线观看免费|