隨筆-9  評論-2  文章-0  trackbacks-0
          import org.eclipse.swt.SWT;
          import org.eclipse.swt.events.SelectionAdapter;
          import org.eclipse.swt.events.SelectionEvent;
          import org.eclipse.swt.layout.GridLayout;
          import org.eclipse.swt.widgets.Combo;
          import org.eclipse.swt.widgets.Display;
          import org.eclipse.swt.widgets.Shell;

          public class ComboTest {

              
          public static void main(String[] args) {
                  String[] WEEK 
          = { "Monday""Tuesday""Wednesday"};
                  Display display 
          = new Display();
                  Shell shell 
          = new Shell(display);
                  shell.setBounds(
          500100500300);
                  shell.setText(
          "Combo");
                  shell.setLayout(
          new GridLayout(3true));
                  
                  
          //創建Combo組件,為下拉列表樣式
                  final Combo dc = new Combo(shell, SWT.DROP_DOWN);
                  dc.setItems(WEEK);
                  dc.addSelectionListener(
          new SelectionAdapter(){
                      @Override
                      
          public void widgetSelected(SelectionEvent e) {
                          String key 
          = ""+dc.getSelectionIndex();
                          String value 
          = dc.getText();
                          System.out.println(
          "key:"+key+"    value:"+value);
                      }
                  });
                  
                  
          //創建Combo組件,為下拉列表樣式,且只讀
                  final Combo rc = new Combo(shell, SWT.DROP_DOWN | SWT.READ_ONLY);
                  
          //在界面中顯示的是123
                  rc.add("123");
                  
          //第一個值是key從0開始 ,第二個值為value
                  rc.setData("0""321");
                  
                  rc.add(
          "456");
                  rc.setData(
          "1""654");
                  
                  rc.addSelectionListener(
          new SelectionAdapter(){
                      @Override
                      
          public void widgetSelected(SelectionEvent e) {
                          String key 
          = ""+rc.getSelectionIndex();
                          System.out.println(
          "key:"+key);
                          String value 
          = (String) rc.getData(key);
                          System.out.println(
          "key:"+key+"    value:"+value);
                      }
                  });
                  
          //rc.setItems(MONTHS);
                  
          //創建Combo組件,為List組件樣式
                  Combo sc = new Combo(shell, SWT.SIMPLE);
                  sc.setItems(WEEK);
                  shell.open();
                  
          while (!shell.isDisposed()) {
                     
          if (!display.readAndDispatch()) {
                         display.sleep();
                    }
               }

               display.dispose();

              }

          }
          posted on 2011-08-02 14:22 secret_x15 閱讀(12906) 評論(0)  編輯  收藏 所屬分類: java
          主站蜘蛛池模板: 理塘县| 青州市| 万全县| 吴川市| 湖南省| 漾濞| 诸城市| 红原县| 英吉沙县| 乐陵市| 团风县| 即墨市| 祁阳县| 洪湖市| 洪雅县| 丁青县| 松潘县| 原阳县| 通榆县| 米泉市| 姚安县| 内黄县| 隆尧县| 蒲城县| 万源市| 桐城市| 同仁县| 于都县| 赞皇县| 安乡县| 松桃| 武义县| 彭州市| 吉木乃县| 金华市| 南靖县| 贵阳市| 博乐市| 陇西县| 阿图什市| 平定县|