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 Container getTopContainer(Component component, Class<Component> lookupClass) {
    Container parent = component.getParent();
    if (parent.getClass().equals(lookupClass)) {
        return parent;
    } else {/*from www . ja  v a  2  s  .c o  m*/
        return getTopContainer(parent, lookupClass);
    }
}

From source file:Util.java

public static void getComponentTreePosition(Component c, ArrayList pos) {
    if (c.getParent() == null) {
        return;/*from   ww  w  . j  a v a  2s .  com*/
    }

    getComponentTreePosition(c.getParent(), pos);

    pos.add(new Integer(c.getParent().getComponentCount() - getComponentIndex(c)));
}

From source file:Main.java

/**
 * Finds the index of a component in its parent container by iterating over
 * all children.//  ww  w .j  av  a2  s  .c  o  m
 * @param component the component must have a parent
 * @return -1 if component is null or has no parent
 */
public static final int getComponentIndex(Component component) {
    if (component != null && component.getParent() != null) {
        Container c = component.getParent();
        for (int i = 0; i < c.getComponentCount(); i++) {
            if (c.getComponent(i) == component) {
                return i;
            }
        }
    }
    return -1;
}

From source file:Main.java

public static final Component getChildAt(Container container, Point p) {
    Component c = container.getComponentAt(p);
    return c == null || c.getParent() != container ? null : c;
}

From source file:Main.java

/**
 * Returns scroll pane for specified component if exists, null otherwise.
 *
 * @param component//  w w w . j a  v  a 2s .  c o  m
 *            component to process
 * @return scroll pane for specified component if exists, null otherwise
 */
public static JScrollPane getScrollPane(final Component component) {
    if (component != null && component.getParent() != null && component.getParent() instanceof JViewport
            && component.getParent().getParent() != null
            && component.getParent().getParent() instanceof JScrollPane) {
        return (JScrollPane) component.getParent().getParent();
    } else {
        return null;
    }
}

From source file:Main.java

/**
 * Returns first parent component which supports dran and drop actions.
 *
 * @param component component to look parent supporting drop for
 * @param <T>       parent supporting drop component class type
 * @return first parent component which supports dran and drop actions
 *//*from   www. j a v a2s. co m*/
public static <T extends JComponent> T getFirstParentSupportingDrop(final Component component) {
    final Container parent = component.getParent();
    if (parent instanceof JComponent) {
        final JComponent c = (JComponent) parent;
        if (c.getTransferHandler() != null) {
            return (T) c;
        }
    }
    return getFirstParentSupportingDrop(parent);
}

From source file:Main.java

public static String getComponentPath(Component c) {
    StringBuffer sb = new StringBuffer();
    Component current = c;
    boolean isFirst = true;
    while (current.getParent() != null) {
        sb.insert(0, (isFirst ? "" : ".") + current.getClass().getSimpleName());
        isFirst = false;/*from w  w w.  j  av a  2s . co  m*/
        current = current.getParent();
    }
    return sb.toString();
}

From source file:Util.java

public static final int getComponentIndex(Component component) {
    if (component != null && component.getParent() != null) {
        Container c = component.getParent();
        for (int i = 0; i < c.getComponentCount(); i++) {
            if (c.getComponent(i) == component)
                return i;
        }/*  ww w . ja v  a2s  .c o  m*/
    }

    return -1;
}

From source file:Main.java

static int getY(final Component component) {
    final int y = component.getY();
    final Component parent = component.getParent();
    if (parent == null) {
        return y;
    } else {// w ww . ja  v  a2 s. c om
        return y + getY(parent);
    }
}

From source file:Main.java

public static Window getWindowForComponent(Component comp) {
    assert comp != null;
    for (; comp != null; comp = comp.getParent()) {
        if (comp instanceof Frame || comp instanceof Dialog) {

            return (Window) comp;
        }/*w w w  .j a  v a2 s . c om*/
    }
    throw new IllegalStateException();
}