get Component Parent - Java java.awt

Java examples for java.awt:Component

Description

get Component Parent

Demo Code


//package com.java2s;

import java.awt.*;

public class Main {
    public static Frame getParent(Component theComponent) {
        // this finds the topmost ancestor parent of a component,;;
        // so that we can give that parent to dialog constructors...;;
        Component currParent = theComponent;
        Frame theFrame = null;/* w  ww  .j  ava 2s.c  o m*/
        while (currParent != null) {
            if (currParent instanceof Frame) {
                theFrame = (Frame) currParent;
                break;
            }
            ;
            currParent = currParent.getParent();
        }
        ;
        return theFrame;
    }
}

Related Tutorials