سؤال

This is about a Netbeans 7.1 platform app. Following this tutorial I added the following to the code of my NodetreeTopComponent, in order to change the context-menu:

 @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);
}

}

Unfortunately, this does exactly nothing. Right-clicking any node in my tree i still get just the default Menu (Copy, Properties). What have i overseen?

Thank you for any suggestions.

هل كانت مفيدة؟

المحلول

...I added the following to the code of my NodetreeTopComponent...

You need to override the getActions() method of your Node not your TopComponent. In the tutorial that you linked to refer to the section titled Actions and Nodes. Step one states:

Override the getActions() method of EventNode as follows

I believe this is where you've gone askew.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top