Example usage for java.awt Container getComponentCount

List of usage examples for java.awt Container getComponentCount

Introduction

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

Prototype

public int getComponentCount() 

Source Link

Document

Gets the number of components in this panel.

Usage

From source file:Main.java

public static void disableNewFolderButton(Container c) {
    int len = c.getComponentCount();
    for (int i = 0; i < len; i++) {
        Component comp = c.getComponent(i);
        if (comp instanceof JButton) {
            JButton b = (JButton) comp;
            Icon icon = b.getIcon();
            if (icon != null && icon == UIManager.getIcon("FileChooser.newFolderIcon"))
                b.setEnabled(false);// w w  w.  ja  v a  2  s  .  c  om
        } else if (comp instanceof Container) {
            disableNewFolderButton((Container) comp);
        }
    }
}

From source file:Main.java

private static JTextField getTexField(Container container) {
    for (int i = 0; i < container.getComponentCount(); i++) {
        Component child = container.getComponent(i);
        if (child instanceof JTextField) {
            return (JTextField) child;
        } else if (child instanceof Container) {
            JTextField field = getTexField((Container) child);
            if (field != null) {
                return field;
            }//  w  ww.  j a  va  2 s .c  o  m
        }
    }
    return null;
}

From source file:Main.java

/**
 * Check if the container is empty.//  ww  w .  ja  v a 2  s .c om
 * 
 * @param container The container.
 * @return A boolean.
 */
public static boolean isEmpty(Container container) {
    return container.getComponentCount() == 0;
}

From source file:Main.java

public static int getIndex(Container parent, Component child) {
    for (int i = 0; i < parent.getComponentCount(); i++) {
        if (child.equals(parent.getComponent(i)))
            return i;
    }/*w w  w .j  a va2s .co m*/
    return -1;
}

From source file:Util.java

public static final Component getVisibleChildAt(Container container, Point p) {
    for (int i = 0; i < container.getComponentCount(); i++) {
        Component c = container.getComponent(i);
        if (c.isVisible() && c.contains(p.x - c.getX(), p.y - c.getY()))
            return c;
    }// w  w  w . j  av  a2 s.c o m

    return null;
}

From source file:Main.java

/**
 * Returns the index of the given component in the given container.
 *
 * @param c the Component to look for//from w  w  w  .  j a va  2 s .c o  m
 * @param container the parent container, where this component is added
 * @return the index of the component in the container or -1 if no such
 * component is contained in the container
 */
public static int getComponentIndex(Component c, Container container) {
    for (int i = 0, count = container.getComponentCount(); i < count; i++) {
        if (container.getComponent(i).equals(c))
            return i;
    }
    return -1;
}

From source file:Main.java

public static void setEnabledForChildren(final Container container, final boolean bEnabled) {
    for (int i = 0; i < container.getComponentCount(); i++) {
        final Component child = container.getComponent(i);
        child.setEnabled(bEnabled);/* www  . j a v a2 s  .  co m*/
    }
}

From source file:Main.java

private static void disassemble(Component component) {
    if (component instanceof Container) {
        Container container = (Container) component;
        int nSubcomponents = container.getComponentCount();
        for (int i = 0; i < nSubcomponents; ++i) {
            disassemble(container.getComponent(i));
        }//from   w  w  w .j  a v a  2s . c o  m
        container.removeAll();
    }
}

From source file:Main.java

public static final int getComponentIndex(final Component component) {
    if (component != null && component.getParent() != null) {
        final Container c = component.getParent();
        for (int i = 0; i < c.getComponentCount(); i++) {
            if (c.getComponent(i) == component) {
                return i;
            }//from ww w. ja va  2s  .  c  o m
        }
    }
    return -1;
}

From source file:Main.java

private static boolean focusFirstFocusableChild(Container c) {
    int len = c.getComponentCount();

    for (int i = 0; i < len; i++) {
        if (focusFirstFocusableComponent(c)) {
            return true;
        }//from w ww. ja v a 2 s.co  m
    }

    return false;
}