我创建了 3 个面板。在我添加的根面板中JTabbedPane
,在我添加的第二个选项卡中Panel
,BorderLayout
最后在BorderLayout.WEST
第三个选项卡中。在第三个里面我添加了一个JTree
with PopupMenu
。
如何在 actionPerformed of 中获取根面板PopupMenu
?
menuItem.addActionListener(new AbstractAction() {
public void actionPerformed(ActionEvent e) {
System.out.println("one:"+tree.getParent().getName());
System.out.println("two:"+tree.getParent().getParent().getName());
System.out.println("three:"+tree.getParent().getParent().getParent().getName());
new UnzipFile(file, file.getParentFile(),
(rootPanel) tree.getParent().getParent().getParent() ).run();
}
});
输出:
Exception in thread "AWT-EventQueue-1" java.lang.ClassCastException: de.util.scanners.view.FileTreePanel
at de.util.scanners.view.FileTreePanel$2$1.actionPerformed(FileTreePanel.java:109)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.AbstractButton.doClick(AbstractButton.java:302)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1050)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1091)
at java.awt.Component.processMouseEvent(Component.java:5517)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3129)
at java.awt.Component.processEvent(Component.java:5282)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3984)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3819)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
one:null
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
two:null
three:null
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1791)
at java.awt.Component.dispatchEvent(Component.java:3819)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at be.azvub.webutil.gui.WebEventQueue.dispatchEvent(WebEventQueue.java:34)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)