當在項目上按下ENTER
時,會調用widgetDefaultSelected
方法。在那裏,ControlEditor
以所選TreeItem
文本作爲其編輯器設置Text
:editor.setEditor(text);
。
這Text
然後才處理當ENTER
或ESC
被按下,並在沒有其他場合。這意味着即使您選擇其他項目,Text
仍然可以顯示其原始內容。
要更改此行爲,您可以修改widgetSelected
方法,以便例如處置Text
,以便它不再可見或使用當前選定的項目更新其文本。
要刪除Text
:
@Override
public void widgetSelected(SelectionEvent e) {
// get the current editor
Text text = (Text) editor.getEditor();
if (text != null && !text.isDisposed()) {
// remove the editor
text.dispose();
}
tree.setSelection(new TreeItem[] { cursor.getRow() });
}
要更新Text
內容:
@Override
public void widgetSelected(SelectionEvent e) {
// get the current editor
Text text = (Text) editor.getEditor();
if (text != null && !text.isDisposed()) {
// update the text in the editor
TreeItem row = cursor.getRow();
int column = cursor.getColumn();
text.setText(row.getText(column));
}
tree.setSelection(new TreeItem[] { cursor.getRow() });
}
由於一噸快速回復!有用 :) – Vrinda