Here you can find the source of getInvoker(final JMenuItem menuItem)
static Component getInvoker(final JMenuItem menuItem)
//package com.java2s; //License from project: Apache License import java.awt.Component; import java.awt.MenuContainer; import java.awt.MenuItem; import javax.swing.JMenuItem; import javax.swing.JPopupMenu; public class Main { static Component getInvoker(final JMenuItem menuItem) { MenuContainer menuContainer = menuItem.getParent(); while (menuContainer != null && !(menuContainer instanceof JPopupMenu)) { if (menuContainer instanceof MenuItem) { menuContainer = ((MenuItem) menuContainer).getParent(); } else { menuContainer = null;// w w w . j a v a 2 s . c om } } if (menuContainer != null) { final JPopupMenu menu = (JPopupMenu) menuContainer; final Component invoker = menu.getInvoker(); return invoker; } else { return null; } } }