import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class ComboTest {
private static Combo combo_2;
private static Combo combo_1;
private static Combo combo;
/**
* Launch the application
* @param args
*/
public static void main(String[] args) {
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setSize(461, 337);
shell.setText("SWT Application");
//
shell.open();
combo = new Combo(shell, SWT.NONE);
combo.setBounds(123, 116, 141, 20);
final Button button = new Button(shell, SWT.NONE);
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
combo.removeAll();//先 清空
for (int i=1; i<=10;i++)
combo.add("第"+i+"字符串");//添加字符串
combo.select(0);//设置第一级为当前项
}
});
button.setText("设值");
button.setBounds(105, 189, 48, 22);
final Button button_1 = new Button(shell, SWT.NONE);
button_1.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
//MessageDialog.openInformation(shell,null,combo.getText());
}
});
button_1.setText("取值");
button_1.setBounds(231, 189, 48, 22);
combo_1 = new Combo(shell, SWT.READ_ONLY);//只读
combo_1.setBounds(313, 52, 52, 20);
combo_2 = new Combo(shell, SWT.SIMPLE);//一直显示
combo_2.setBounds(313, 164, 52, 20);
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
}
posted on 2008-03-31 07:09
hakuci 阅读(268)
评论(0) 编辑 收藏