• Combo


    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(500, 100, 500, 300);
            shell.setText("Combo");
            shell.setLayout(new GridLayout(3, true));
            
            //创建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();
    
        }
    }
  • 相关阅读:
    Python中的traceback模块
    硬链接和软连接的区别
    Python中的fileinput模块和tempfile模块
    SQL Relay
    使用python+cron对php状态进行定时监控
    给想学习asp小朋友的建议
    emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
    python非贪婪、多行匹配正则表达式例子[转载]
    python中eval, exec, execfile,和compile [转载]
    url extracting 未测试
  • 原文地址:https://www.cnblogs.com/sandyflower/p/3628171.html
Copyright © 2020-2023  润新知