find JFrame - Java Swing

Java examples for Swing:JFrame

Description

find JFrame

Demo Code


//package com.java2s;
import java.awt.Component;
import javax.swing.JFrame;

public class Main {
    public static JFrame findJFrame(Component myComponent) {
        Component currentParent = myComponent;
        JFrame myFrame = null;/*from   w  w w.j  a  v  a2 s .c o m*/

        while (currentParent != null) {
            if (currentParent instanceof JFrame) {
                myFrame = (JFrame) currentParent;
                break;
            }
            currentParent = currentParent.getParent();
        }
        return myFrame;
    }
}

Related Tutorials