关于JMenuItem的getParent()方法~

我的JMenuItem是加在JMenu里边的,为什么调用JMenuItem的getParent()的时候返回来的是JPopupMenu?而不是JMenuItem?

 


问题补充:
怎么设置Parent?

[color=blue]Swing中通过JMenuItem取得主窗口句柄2008年04月01日 星期二 下午 02:38// 为了降低耦合度,避免多余的主窗口句柄传递,可以使用这里的方法获取主窗口句柄

JMenuItem mi = (JMenuItem)e.getSource(); // e是事件监听方法中的事件参数(ActionEvent)
JMenu jm = (JMenu)mi.getAccessibleContext().getAccessibleParent(); // 如果使用mi.getParent(),得到的竟然是JPopupMenu对象,十分之不和谐呀^ ^
MainFrame mf = (MainFrame)jm.getRootPane().getParent(); // 对形如JButton之类的对象使用getRootPane().getParent()方法可以取得主窗口的句柄。 [/color]
[quote]This problem is caused by the fact that the
implementation of JMenu doesn't add a JMenuItem
to itself: It adds a JMenuItem to one of its
private member which is a JPopupMenu.[/quote]
参见如下网址:
[url]http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4103931[/url]

确定JMenuItem设置的parent是JMenu!?

JMenu是JMenuItem的子类啊,

这个getParent不是得到父类,是获得此组件的父级。