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
请先登录再写评论。
Hello Dhwani,
The correct way to show a JPopupMenu is to use the show() method and to pass
your JTable as 'invoker' parameter.
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
Thanks Dmitry,
That did it. :)
thanks
dk