我有一個可編輯的SWT組合。用戶可以從下拉列表中選擇一個項目或輸入新的文本。我的代碼也做了一些數據驗證,如果輸入的文本無效,我想強調焦點到組合以及突出顯示輸入的文本。SWT可編輯組合 - 高亮文本
我的問題是:有沒有辦法突出顯示組合中的所有輸入文本?不幸的是,我認爲沒有「selectText」方法...
在此先感謝。
我試圖巴茲的建議,但不知什麼原因,該代碼同時工作在一個單獨的測試項目,同樣的代碼並不在我的計劃工作:
comboViewerRes = new ComboViewer(this, SWT.DROP_DOWN);
comboRes = comboViewerRes.getCombo();
comboRes.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false,
1, 1));
comboRes.addListener(SWT.KeyUp, new Listener() {
@Override
public void handleEvent(Event e) {
if (e.keyCode == SWT.SPACE) {
Rectangle bounds = comboRes.getBounds();
Point point = new Point(bounds.x, bounds.x + bounds.width);
System.out.println(point);
comboRes.setSelection(point);
}
}
});
發佈您嘗試使用的代碼。有些人會糾正它並回答 –