Java tutorial
//package com.java2s; // The MIT License (MIT) import java.awt.Component; import java.awt.Container; import javax.swing.JPopupMenu; public class Main { /** * Return the parent of a component. If the component is a popup menu and its parent is null then return its invoker. */ public static Component getParent(Component component) { Container parent = component.getParent(); if (parent == null && component instanceof JPopupMenu) { return ((JPopupMenu) component).getInvoker(); } return parent; } }