Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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