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) {
        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(
at javax.swing.AbstractButton.fireActionPerformed(
at javax.swing.AbstractButton$Handler.actionPerformed(
at javax.swing.DefaultButtonModel.fireActionPerformed(
at javax.swing.DefaultButtonModel.setPressed(
at javax.swing.AbstractButton.doClick(
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(
at java.awt.Component.processMouseEvent(
at javax.swing.JComponent.processMouseEvent(
at java.awt.Component.processEvent(
at java.awt.Container.processEvent(
at java.awt.Component.dispatchEventImpl(
at java.awt.Container.dispatchEventImpl(
at java.awt.Component.dispatchEvent(
at java.awt.LightweightDispatcher.retargetMouseEvent(
at java.awt.LightweightDispatcher.processMouseEvent(
at java.awt.LightweightDispatcher.dispatchEvent(
at java.awt.Container.dispatchEventImpl(
at java.awt.Window.dispatchEventImpl(
at java.awt.Component.dispatchEvent(
at java.awt.EventQueue.dispatchEvent(
at be.azvub.webutil.gui.WebEventQueue.dispatchEvent(
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(
at java.awt.EventDispatchThread.pumpEventsForHierarchy(
at java.awt.EventDispatchThread.pumpEvents(
at java.awt.EventDispatchThread.pumpEvents(


You could use the SwingUtilities.getAncestorOfClass method.

I think is not a good idea get the chain of parents trying to lookup for a specific component to update it. What if you want to put that JTree in other place, or simply restructure your layout. You will be forced to change all of that things.

You could try with MVC. The JTree sends an event to the Controller that will have interfaces to the JTree itself and to the root pane. When you instantiate your controller pass all views as collaborators of the controller.

I don't know where your panels are instantiated. But if you instantiate your controller at root level should be easy get references to all components you need.

Need Your Help

Webspher server ports not behaving as expected

websphere admin rad ports

In WAS, the admin console is usually accessed at the url : https://localhost:9043/console. Now I just wanted to know where from this 9043 came about. So I go to Servers--> Application Servers --...

PHP how to find uppercase in array

php uppercase lowercase

I have an array with many words, but some senteces are in uppercase. For example:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.