Example usage for java.awt Container getComponents

List of usage examples for java.awt Container getComponents

Introduction

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

Prototype

public Component[] getComponents() 

Source Link

Document

Gets all the components in this container.

Usage

From source file:Main.java

private static Component[] getComponents(Container container) {
    return container instanceof JMenu ? ((JMenu) container).getMenuComponents() : container.getComponents();
}

From source file:Main.java

public static Component find(Container parent, String name, Class reqClass) {
    Component[] kids = parent.getComponents();
    for (int x = 0; x < kids.length; x++) {
        if (name.equals(kids[x].getName()) && reqClass == kids[x].getClass()) {
            return kids[x];
        } else if (kids[x] instanceof Container) {
            Component c = find((Container) kids[x], name);
            if (c != null) {
                return c;
            }/*  w  ww .j  a  va 2s. co m*/
        }
    }
    return null;
}

From source file:Main.java

static void setDescendantsEnabled(final Component component, final boolean enabled) {
    if (component != null) {
        component.setEnabled(enabled);/*from w w  w  .  j av a 2s  . com*/
        if (component instanceof Container) {
            final Container container = (Container) component;
            for (final Component child : container.getComponents()) {
                setDescendantsEnabled(child, enabled);
            }
        }
    }
}

From source file:Main.java

/**
 * Returns whether atleast one of child components within the specified
 * container is focusable or not.//from w  ww .j  ava  2 s  .c om
 *
 * @param container
 *            container to process
 * @return true if atleast one of child components within the specified
 *         container is focusable, false otherwise
 */
public static boolean hasFocusableComponent(final Container container) {
    for (final Component component : container.getComponents()) {
        if (component.isFocusable()) {
            return true;
        } else if (component instanceof Container) {
            if (hasFocusableComponent((Container) component)) {
                return true;
            }
        }
    }
    return false;
}

From source file:Main.java

public static Component[] getComponents(final Container container) {
    synchronized (container.getTreeLock()) {
        return container.getComponents();
    }//from  w ww .ja  v  a  2  s. co m
}

From source file:Main.java

private static JComponent getComponentWithName(Container owner, String name, Class<?> clazz) {
    for (Component c : owner.getComponents()) {
        if (clazz.isInstance(c) && ((JComponent) c).getName() != null
                && ((JComponent) c).getName().equals(name))
            return (JComponent) c;
        else if (c instanceof JComponent) {
            JComponent b = getComponentWithName((JComponent) c, name, clazz);
            if (b != null)
                return b;
        }/*from  ww  w . ja  va 2  s.co  m*/
    }
    return null;
}

From source file:Main.java

public static int getComponentIndex(Container container, Component component) {
    int index = 0;
    for (Component comp : container.getComponents()) {
        if (comp == component)
            return index;
        ++index;//ww  w  . ja va2 s  . c  o m
    }
    return -1;
}

From source file:Main.java

/**
 * Gets the index of the component inside the given panel.
 * //from   ww  w.  j  a va2  s.c o  m
 * @param container
 *            The container where the components is located
 * @param comp
 *            The components to find the index of
 * 
 * @return The index of the component in the given panel, or -1 if the
 *         component was not found in the panel or the panel contains no
 *         components.
 */
public static int indexOfComponent(Container container, Component comp) {
    Component[] components = container.getComponents();
    for (int i = 0; i < components.length; i++) {
        if (components[i] == comp) {
            return i;
        }
    }

    return -1;
}

From source file:Main.java

public static List getChildJComponents(Container container) {
    List result = new ArrayList();

    Component[] children = container.getComponents();

    for (int i = 0; i < children.length; i++) {
        if (children[i] instanceof JComponent) {
            result.add(children[i]);/*from  ww w . ja  v a2  s .  c  o  m*/
            result.addAll(getChildJComponents((JComponent) children[i]));
        }
    }

    return result;
}

From source file:Main.java

/**
 * Resizes the icons of all the abstract buttons which are contained in
 * a container.//from   w w  w  .j a v  a 2s  . c  o  m
 * 
 * @param container a container containing abstract buttons
 * @param size the size which should be used for the icons
 */
public static void scaleAllAbstractButtonIconsOf(Container container, int size) {
    for (final Component c : container.getComponents()) {
        if (c instanceof AbstractButton) {
            final ImageIcon i = (ImageIcon) ((AbstractButton) c).getIcon();
            if (i != null) {
                i.setImage(i.getImage().getScaledInstance(size, size, Image.SCALE_SMOOTH));
            }
        }
    }
}