Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//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;
            }
        }
        if (menuContainer != null) {
            final JPopupMenu menu = (JPopupMenu) menuContainer;
            final Component invoker = menu.getInvoker();
            return invoker;
        } else {
            return null;
        }

    }
}