2012-02-08 46 views
0

這是關於Netbeans 7.1平臺的應用程序。繼this tutorial我增加了以下我NodetreeTopComponent的代碼,以改變上下文菜單:更改NodeTree的彈出菜單

@Override 
public Action[] getActions() { 
    return new Action[] {new MyAction()}; 
} 

private static class MyAction extends AbstractAction { 

    public MyAction() { 
    putValue (NAME, "New Whatever"); 
} 

@Override 
public void actionPerformed(ActionEvent e) { 
    NewWhateverTopComponent nk = new NewWhateverTopComponent(); 
    nk.setVisible(true); 
} 

} 

不幸的是,這不正是什麼。右鍵單擊我樹中的任何節點,我仍然只獲取默認菜單(複製,屬性)。我監督了什麼?

謝謝你的任何建議。

回答

1

...我增加了以下我NodetreeTopComponent的代碼...

你需要重寫你的節點不是你TopComponentgetActions()方法。在您鏈接的教程中,請參閱標題爲Actions and Nodes的部分。步驟一的狀態:

覆蓋EventNode的的getActions()方法如下

我相信這是你到哪兒去了那副。

+0

你是對的。非常感謝。 – 2012-02-09 08:27:07

+0

不客氣,祝你好運。 Node API是要掌握的更具挑戰性的NetBeans API之一。 – 2012-02-09 13:18:34