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;

public class Main {
    /**
     * Finds the top level parent (frame/dialog/window) of any component
     * @param component Component
     * @return Parent or null if none found
     */
    public static Component getTopLevelParent(Object component) {
        Component top = null;

        if (component instanceof Component) {
            Component c = (Component) component;

            while (c.getParent() != null) {
                c = c.getParent();
            }
            top = c;
        }

        return top;
    }
}