public static void showCombo(Shell shell) {
final Combo combo = new Combo(shell, SWT.SIMPLE);
String[] items = new String[4];
for (int i = 0; i < items.length; i++) {
items[i] = "选项" + i;
}
combo.setItems(items);
// 注册键盘事件
combo.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
// 如果单击了向左的箭头按键,则选中上一个选项
if (e.keyCode == SWT.ARROW_LEFT) {
combo.select(combo.getSelectionIndex() - 1);
} else if (e.keyCode == SWT.ARROW_RIGHT) {
// 如果单击了向右的箭头按键,则选中下一个选项
combo.select(combo.getSelectionIndex() + 1);
}
}
});
}