Example usage for java.awt Container getParent

List of usage examples for java.awt Container getParent

Introduction

In this page you can find the example usage for java.awt Container getParent.

Prototype

public Container getParent() 

Source Link

Document

Gets the parent of this component.

Usage

From source file:Main.java

public static Frame getParentFrame(Container container) {
    Container parent = container.getParent();

    while ((parent != null) && !(parent instanceof Frame)) {
        parent = parent.getParent();//w ww . j  a  v  a2 s. c  om
    }

    return (Frame) parent;
}

From source file:Main.java

public static Container findContainer(Component thisComp, Class<? extends Container> containerClass) {
    if (thisComp == null) {
        return null;
    }//from   w ww .  ja  va 2s  .c  o m
    Container parent = thisComp.getParent();
    do {
        parent = parent.getParent();
        if (parent != null && containerClass.isAssignableFrom(parent.getClass())) {
            return parent;
        }
    } while (parent != null);
    return null;
}

From source file:Main.java

/**
 * Generic-ified version of SwingUtilities.getAncestorOfClass()
 *///from  w w w  .  j  a v  a  2 s . c om
public static <T> T getAncestorOfClass(Class<T> c, Component comp) {
    if (comp == null || c == null)
        return null;
    Container parent = comp.getParent();
    while (parent != null && !(c.isInstance(parent)))
        parent = parent.getParent();
    return (T) parent;
}

From source file:Main.java

public static Frame getOwnerFrame(Component component) {
    if (component instanceof Frame) {
        return (Frame) component;
    }//from  ww  w .j  a  va  2s .  c  om
    Container parent = component.getParent();
    while (!(parent instanceof Frame)) {
        parent = parent.getParent();
        if (parent == null) {
            throw new IllegalArgumentException("Component has no root Frame.");
        }
    }
    return (Frame) parent;
}

From source file:Main.java

/**
 * Finds the real bounds of the component relative to the root Window
 *
 * @param container The container to find the bounds for.
 * @param rect A Rectangle to store the bounds in. This same object is
 *             returned.// w ww  .jav  a  2 s .  c o  m
 * @return The real bounds of the container.
 */
public static Rectangle getRealBounds(Container container, Rectangle rect) {
    container.getBounds(rect);
    for (Container c = container.getParent(); !(c instanceof Window); c = c.getParent()) {
        Point p = c.getLocation();
        rect.x += p.x;
        rect.y += p.y;
    }
    return rect;
}

From source file:Main.java

public static Window getOwnerWindow(Component component) {
    if (component instanceof Window) {
        return (Window) component;
    }/*from  ww  w. j  a  v  a 2 s . c om*/
    Container parent = component.getParent();
    while (!(parent instanceof Window)) {
        parent = parent.getParent();
        if (parent == null) {
            throw new IllegalArgumentException("Component has no root window.");
        }
    }
    return (Window) parent;
}

From source file:Main.java

/**
 * Returns the parent <code>JFrame</code> of the specified component.
 * //  ww w.  j  av a 2s .  co  m
 * @param component the component to find the parent JFrame for.
 * @return the parent JFrame.
 */
public static JFrame getParentJFrame(Component component) {
    if ((component == null) || (component instanceof JFrame)) {
        return (JFrame) component;
    }
    Container c = component.getParent();
    while ((c != null) && !(c instanceof JFrame)) {
        c = c.getParent();
    }
    return (JFrame) c;
}

From source file:Main.java

/**
 * Finds the Frame containing this component, or null if none found.
 * @param component the component to search
 * @return the Frame containing the component
 *///from   w  ww . ja  v a2s  .  c  o  m
public static Frame findContainingFrame(Component component) {
    Container container = component.getParent();
    while (container != null && !(container instanceof Frame)) {
        container = container.getParent();
    }
    return (Frame) container;
}

From source file:Main.java

/**
 * Finds the Dialog containing this component, or null if none found.
 * @param component the component to search
 * @return the Dialog containing the component
 *///  w w w .j  av  a  2s  .  com
public static Dialog findContainingDialog(Component component) {
    Container container = component.getParent();
    while (container != null && !(container instanceof Dialog)) {
        container = container.getParent();
    }
    return (Dialog) container;
}

From source file:Main.java

/**
 * Finds the Window containing this component, or null if none found.
 * @param component the component to search
 * @return the Window containing the component
 *//*  ww w . j a va  2s .co  m*/
public static Window findContainingWindow(Component component) {
    Container container = component.getParent();
    while (container != null && !(container instanceof Window)) {
        container = container.getParent();
    }
    return (Window) container;
}