Java JMenuItem getInvoker(final JMenuItem menuItem)

Here you can find the source of getInvoker(final JMenuItem menuItem)

Description

get Invoker

License

Apache License

Declaration

static Component getInvoker(final JMenuItem menuItem) 

Method Source Code

//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;
        }

    }
}

Related

  1. createJMenuItem(JMenu menu, String text, int mnemonic, int acceleratorKey, String toolTip, ActionListener actionListener)
  2. createMenu(JMenuItem[] items, String name, String description, int mnemonic)
  3. exit(JMenuItem anItem)
  4. getForeground(final BasicMenuItemUI ui, final JMenuItem menuItem)
  5. getIconPlaceholderWidth(final JMenuItem menuItem, final boolean alignTextToMenuIcons)
  6. getJMenuItem(String name, JMenuBar jmenubar)
  7. getMenuItemParent(JMenuItem menuItem)
  8. getTopLevelMenu(JMenuItem menuitem)
  9. layoutMenuItem(JMenuItem menuItem, FontMetrics fm, String text, FontMetrics fmAccel, String acceleratorText, Icon icon, Icon checkIcon, Icon arrowIcon, int verticalAlignment, int horizontalAlignment, int verticalTextPosition, int horizontalTextPosition, Rectangle viewRect, Rectangle iconRect, Rectangle textRect, Rectangle acceleratorRect, Rectangle checkIconRect, Rectangle arrowIconRect, int textIconGap, int menuItemGap)