get parent Frame from Component - Java Swing

Java examples for Swing:JFrame

Description

get parent Frame from Component

Demo Code


//package com.java2s;

import java.awt.*;

public class Main {
    public static Frame getFrame(Component theComponent) {
        Component currParent = theComponent;
        Frame theFrame = null;//  w w w.j a v a  2 s .c  om
        while (currParent != null) {
            if (currParent instanceof Frame) {
                theFrame = (Frame) currParent;
                break;
            }
            currParent = currParent.getParent();
        }
        return theFrame;
    }
}

Related Tutorials