SWT之Combo的使用

SWT中的list,可以只读,也可以允许用户输入。

代码如下:

 

import org.eclipse.swt.SWT; 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 TestCombo { public static void main(String[] args) { String[] MONTHS = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October" }; Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new GridLayout(3, true)); // 创建Combo组件,为下拉列表样式 Combo dc = new Combo(shell, SWT.DROP_DOWN); dc.setItems(MONTHS); // 创建Combo组件,为下拉列表样式,且只读 Combo rc = new Combo(shell, SWT.DROP_DOWN | SWT.READ_ONLY); rc.setItems(MONTHS); // 创建Combo组件,为List组件样式 Combo sc = new Combo(shell, SWT.SIMPLE); sc.setItems(MONTHS); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); } }

你可能感兴趣的:(String,shell,list,Class,import,SWT)