2017-02-15 40 views
0

我用從TreeCursor文檔相同的例子試圖從小區選擇的文本: http://git.eclipse.org/c/platform/eclipse.platform.swt.git/plain/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet360.javaEclipse的SWT TreeCursor總是有被選爲第一次

在哪個小區我按回車鍵(SWT.CR)首次,說我在單元格'root11'上按下,在此之後,單擊'root11'出現在單元格中。 我的要求是從一個單元格中選擇要複製的文本。我不想編輯。所以每當我點擊一個單元格來複制其文本時,就會出現第一次選擇的單元格中的文本。

任何可能導致此問題的指針? 在此先感謝!

回答

0

當在項目上按下ENTER時,會調用widgetDefaultSelected方法。在那裏,ControlEditor以所選TreeItem文本作爲其編輯器設置Texteditor.setEditor(text);

Text然後才處理當ENTERESC被按下,並在沒有其他場合。這意味着即使您選擇其他項目,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() }); 
} 
+0

由於一噸快速回復!有用 :) – Vrinda