how to get parent panel in java?

I have created 3 panels. In the root panel I have added JTabbedPane, inside one of the tabs I have added second Panel with BorderLayout and finally in the BorderLayout.WEST the 3rd one. Inside the 3rd one I have added a JTree with PopupMenu.

How can I get root panel inside 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();
    }
});

output:

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)

Answers


You could use the SwingUtilities.getAncestorOfClass method.


Need Your Help

Where do I get a thread-safe CollectionView?

.net wpf multithreading thread-safety collectionview

When updating a collection of business objects on a background thread I get this error message: