它似乎是well-known使用JMenuItem.getRootPane()时有一个错误。 我读了错误描述,但我找不出解决方法。 您是否知道Action.actionPerformed()方法中的解决方法?JMenuItem.getRootPane()解决方法?
更新:我现在得到这个,但不适用于子菜单。
public void actionPerformed(ActionEvent e) {
Component c = (Component) e.getSource();
if (c instanceof JMenuItem) {
c = ((JPopupMenu)((JMenuItem)c).getParent()).getInvoker();
}
Component z = SwingUtilities.getRootPane(c);
}
我有这个之前,但我不认为代码是重要的更容易阅读,我不能使用默认的Action构造w/o参数。谢谢。 – PeterMmm 2009-08-31 09:56:32