Problem while showing popup menus.

Hi,

I need to popup a menu on a JTable. For this I am using the following inside a MouseAdapter.mouseClicked(...) method.

ActionPopupMenu menu = ActionManager.getInstance().createActionPopupMenu("Transaction Table", transactionsPopupGroup);
menu.getComponent().setVisible(true);

The transactionsPopupGroup used above is created as follows.

private DefaultActionGroup createTransactionsPopupGroup() {
DefaultActionGroup group = new DefaultActionGroup("history_trans_popup", true);

group.add(new AnAction("Action1", "Action 1 description", null) {

public void actionPerformed(AnActionEvent e) {
// TODO
}

public void update(AnActionEvent e) {
e.getPresentation().setEnabled(Action1Flag);
}
});

// this is to add a sub menu under the popup menu
DefaultActionGroup subGrp = new DefaultActionGroup("SubAction", true);
subGrp.add(new AnAction("Other Version", "SubAction description", null) {

public void actionPerformed(AnActionEvent e) {
// TODO
}

public void update(AnActionEvent e) {
e.getPresentation().setEnabled(subActionFlag);
}
});
group.add(subGrp);

return group;
}

The problem is that when I right click on the JTable I get the attached Exception and stack trace. The DataContext object on the AnActionEvent presumable is null. But I am not able to make out the cause of this problem. What could be the cause of this?



Attachment(s):
StackTrace.txt
2 comments
Comment actions Permalink

Hello Dhwani,

The correct way to show a JPopupMenu is to use the show() method and to pass
your JTable as 'invoker' parameter.

I need to popup a menu on a JTable. For this I am using the following
inside a MouseAdapter.mouseClicked(...) method.

ActionPopupMenu menu =
ActionManager.getInstance().createActionPopupMenu("Transaction Table",
transactionsPopupGroup);
menu.getComponent().setVisible(true);


--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

Thanks Dmitry,
That did it. :)

thanks
dk

0

Please sign in to leave a comment.