find Parent Frame - Java Swing

Java examples for Swing:JFrame

Description

find Parent Frame

Demo Code


//package com.java2s;
import java.awt.Component;
import java.awt.Container;

import java.awt.Frame;

public class Main {
    public static Frame findParentFrame(Component component) {
        if (component == null) {
            throw new NullPointerException("component == null");
        }/*w  w w .j a va 2s.  com*/
        Container parent = component.getParent();
        while (parent != null) {
            if ((parent instanceof Frame)) {
                return (Frame) parent;
            }
            parent = parent.getParent();
        }
        return null;
    }
}

Related Tutorials