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 boolean isOnlyVisibleComponent(Component c) {
    return c != null && c.isVisible() && getVisibleChildrenCount(c.getParent()) == 1;
}

From source file:Main.java

/**
 * Generic-ified version of SwingUtilities.getAncestorOfClass()
 *//*from   w w w .j  a  v a  2 s  .co  m*/
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 Component findParent(Component c) {
    if (c == null)
        return null;
    Component parent = c.getParent();
    Component comp = null;/*from   w  ww. java  2s. co m*/
    while (parent != null) {
        comp = parent;
        parent = comp.getParent();
    }
    return comp;
}

From source file:Win.java

public static Frame findFrame(Component comp) {
    for (; comp != null; comp = comp.getParent())
        if (comp instanceof Frame) {
            return (Frame) comp;
        }/*from   w ww.  j a  v  a2s  .com*/
    return null;
}

From source file:Main.java

/**
 * Returns first parent which is instance of specified class type or null if
 * none found./*w  w w  . ja va 2 s. c om*/
 *
 * @param component
 *            component to look parent for
 * @param parentClass
 *            parent component class
 * @param <T>
 *            parent component class type
 * @return first parent which is instance of specified class type or null if
 *         none found
 */
public static <T extends Container> T getFirstParent(final Component component, final Class<T> parentClass) {
    Component parent = component.getParent();
    while (!parentClass.isInstance(parent) && parent != null) {
        parent = parent.getParent();
    }
    return (T) parent;
}

From source file:Main.java

/**
 * Returns the top component from a component.
 * // ww  w  .j  ava2  s .c  om
 * @return The top component.
 * @param cmp A component.
 */
public static Component getTopComponent(Component cmp) {
    if (cmp == null) {
        return null;
    }
    while (cmp.getParent() != null) {
        cmp = cmp.getParent();
    }
    return cmp;
}

From source file:Main.java

/**
 * Tests whether the component passed in parameter is used as an editor.
 *
 * @param comp//  ww w . j a  v  a2  s . co  m
 *          the component to test.
 * @return true if the component is currently used as an editor.
 */
public static boolean isUsedAsEditor(Component comp) {
    boolean usedAsEditor = false;
    Container parent = comp.getParent();
    while (parent != null && !usedAsEditor) {
        if (parent instanceof JTable) {
            usedAsEditor = true;
        }
        parent = parent.getParent();
    }
    return usedAsEditor;
}

From source file:Main.java

public static JFrame getJFrame(Component c) {
    Component ret = c;
    while (ret != null && !(ret instanceof JFrame)) {
        ret = ret.getParent();
    }//w ww  . j  a v a2  s. c  o  m
    return (JFrame) ret;
}

From source file:Main.java

/**
 * Get the {@link JScrollPane} that surrounds the given component.
 * @return The desired {@link JScrollPane} or <code>null</code> if no {@link JScrollPane} could be found.
 *///  w w w. j  a  v  a  2s . co  m
public static JScrollPane getSurroundingScrollPane(Component comp) {
    JScrollPane fScrollPane = null;
    while (comp != null) {
        comp = comp.getParent();
        if (comp instanceof JScrollPane) {
            fScrollPane = (JScrollPane) comp;
            break;
        }
    }
    return fScrollPane;
}

From source file:Main.java

public static Container findAncestorScrollPane(Component p) {
    if ((p == null) || !(p instanceof Container)) {
        return null;
    }/*from  ww  w  .  jav a 2  s  . com*/

    Container c = p.getParent();

    return findAncestorScrollPane(c);
}