Changing the popup-menu of a NodeTree
-
27-04-2021 - |
سؤال
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.
لا تنتمي إلى StackOverflow