代码之家  ›  专栏  ›  技术社区  ›  Mrityunjay

Eclipse小部件组合选项上的自动选择

  •  0
  • Mrityunjay  · 技术社区  · 7 年前

    我想在默认情况下选择widget combo first选项,它处于只读模式。有什么建议吗

    1 回复  |  直到 7 年前
        1
  •  1
  •   greg-449    7 年前

    这个 select 方法 Combo 设置选定项目。

    Combo combo = new Combo(parent, SWT.READ_ONLY | SWT.DROP_DOWN);
    
    combo.setItems(... items array ....);
    
    // Select first item
    combo.select(0);
    

    请注意,这不会生成选择更改事件。为此,您需要使用 notifyListeners

    Event event = new Event();
    event.widget = combo;
    event.display = combo.getDisplay();
    event.type = SWT.Selection;
    combo.notifyListeners(SWT.Selection, event);