public boolean isMenuBarPopup(Component c) { boolean menuBarPopup = false; if (c instanceof JPopupMenu) { JPopupMenu pm = (JPopupMenu) c; if (pm.getInvoker() != null) { menuBarPopup = (pm.getInvoker().getParent() instanceof JMenuBar); } } return menuBarPopup; }
/** * Returns the popup menu which is at the root of the menu system for this popup menu. * * @return the topmost grandparent <code>JPopupMenu</code> */ JPopupMenu getRootPopupMenu() { JPopupMenu mp = this; while ((mp != null) && (mp.isPopupMenu() != true) && (mp.getInvoker() != null) && (mp.getInvoker().getParent() != null) && (mp.getInvoker().getParent() instanceof JPopupMenu)) { mp = (JPopupMenu) mp.getInvoker().getParent(); } return mp; }