Example usage for java.awt Component getParent

List of usage examples for java.awt Component getParent

Introduction

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

Prototype

public Container getParent() 

Source Link

Document

Gets the parent of this component.

Usage

From source file:Main.java

public static Window getWindowAncestor(Component c) {
    for (Container p = c.getParent(); p != null; p = p.getParent()) {
        if (p instanceof Window) {
            return (Window) p;
        }//from ww  w .  ja va 2s .c  o m
    }
    return null;
}

From source file:Main.java

public static JViewport getViewportAncestor(Component c) {
    for (Container p = c.getParent(); p != null; p = p.getParent()) {
        if (p instanceof JViewport) {
            return (JViewport) p;
        }/*w w w  . j  av a2 s .c  o  m*/
    }
    return null;
}

From source file:Main.java

public static boolean isRootComponent(Component root) {
    Container parent = root.getParent();
    return parent == null;
}

From source file:Main.java

public static Frame getFrameOwner(Component c) {
    Container parent = c.getParent();
    while (parent != null && !(parent instanceof Frame)) {
        System.out.println("PARENT " + parent);
        parent = parent.getParent();/*w  w w.j  av  a2s. c o m*/
    }
    if (parent != null) {
        return (Frame) parent;
    } else {
        return null;
    }
}

From source file:Main.java

public static void removeButtons(Component comp) {
    if (comp instanceof AbstractButton) {
        comp.getParent().remove(comp);
    }//from  w ww  .j a  va 2s .c  o  m
    if (comp instanceof Container) {
        Component[] comps = ((Container) comp).getComponents();
        for (int x = 0, y = comps.length; x < y; x++) {
            removeButtons(comps[x]);
        }
    }
}

From source file:Main.java

/**
 * Return the parent of a component. If the component is a popup menu and its parent is null then return its invoker.
 *//*w w  w  .j a  v  a  2s.co m*/
public static Component getParent(Component component) {
    Container parent = component.getParent();
    if (parent == null && component instanceof JPopupMenu) {
        return ((JPopupMenu) component).getInvoker();
    }
    return parent;
}

From source file:Main.java

public static Component getRootPane(Component p_component) {
    Component rootPane = p_component.getParent();
    for (; rootPane != null;) {
        if (rootPane.getParent() == null) {
            break;
        }//  ww w. j  av  a2 s  .c o  m
        rootPane = rootPane.getParent();
    }
    return rootPane;
}

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
 *//*from  ww w  .  ja v  a 2  s  . co m*/
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 Frame containing this component, or null if none found.
 * @param component the component to search
 * @return the Frame containing the component
 *//*  ww  w .j  a  v a 2s  .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 Window containing this component, or null if none found.
 * @param component the component to search
 * @return the Window containing the component
 *///  w w w  .jav a2s.  c o  m
public static Window findContainingWindow(Component component) {
    Container container = component.getParent();
    while (container != null && !(container instanceof Window)) {
        container = container.getParent();
    }
    return (Window) container;
}