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

/**
 * Returns map of container child components preferred sizes.
 *
 * @param container// w  w w .j ava  2 s  .com
 *            container to process
 * @return map of container child components preferred sizes
 */
public static Map<Component, Dimension> getChildPreferredSizes(final Container container) {
    final int cc = container.getComponentCount();
    final Map<Component, Dimension> cps = new HashMap<Component, Dimension>(cc);
    for (int i = 0; i < cc; i++) {
        final Component component = container.getComponent(i);
        cps.put(component, component.getPreferredSize());
    }
    return cps;
}

From source file:Main.java

public static int getContainerWidth(Container container) {
    int width = 0;
    for (int index = 0; index < container.getComponentCount(); index++) {
        int offset = (container.getComponent(index).getX() + container.getComponent(index).getWidth());
        if (offset > width) {
            width = offset;/*www  .  j a  v  a  2s  .  c om*/
        }
    }
    return width;
}

From source file:Main.java

public static int getContainerHeight(Container container) {
    int height = 0;
    for (int index = 0; index < container.getComponentCount(); index++) {
        int offset = (container.getComponent(index).getY() + container.getComponent(index).getHeight());
        if (offset > height) {
            height = offset;//from   ww w.  ja va  2  s.c om
        }
    }
    return height;
}

From source file:Main.java

public static void disableBuffer(Component comp, ArrayList<JComponent> dbcomponents) {
    if ((comp instanceof JComponent) && comp.isDoubleBuffered()) {
        JComponent jcomponent = (JComponent) comp;

        dbcomponents.add(jcomponent);//from   w w  w  .j a v a2s  . c o m
        jcomponent.setDoubleBuffered(false);
    }

    if (comp instanceof Container) {
        Container container = (Container) comp;
        int count = container.getComponentCount();

        if (count > 0) {
            for (int i = 0; i < count; i++) {
                Component component = container.getComponent(i);

                disableBuffer(component, dbcomponents);
            }
        }
    }
}

From source file:Main.java

public static final int getComponentIndex(Component component) {
    if (component != null && component.getParent() != null) {
        Container currentComponent = component.getParent();
        for (int index = 0; index < currentComponent.getComponentCount(); index++) {
            if (currentComponent.getComponent(index) == component)
                return index;
        }/*w w  w .j  a  v a 2s.  c  o m*/
    }
    return -1;
}

From source file:Main.java

/**
 * Finds the index of a component in its parent container by iterating over
 * all children.//from w w  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 int getVisibleChildrenCount(Component c) {
    if (c == null || !(c instanceof Container))
        return 0;

    int count = 0;
    Container container = (Container) c;

    for (int i = 0; i < container.getComponentCount(); i++)
        if (container.getComponent(i).isVisible())
            count++;//from  w  w  w .  j av  a  2s  .  c  o  m

    return count;
}

From source file:Util.java

public static int countComponents(Container c) {
    int num = 1;//from   w  w  w. j av  a 2 s . c  o m
    for (int i = 0; i < c.getComponentCount(); i++) {
        Component comp = c.getComponent(i);
        if (comp instanceof Container)
            num += countComponents((Container) comp);
        else
            num++;
    }

    return num;
}

From source file:Main.java

public static Component findFirstComponentOfType(Component comp, Class c) {
    if (c.isInstance(comp))
        return comp;

    if (comp instanceof Container) {
        Container container = (Container) comp;
        for (int i = 0; i < container.getComponentCount(); i++) {
            Component comp2 = findFirstComponentOfType(container.getComponent(i), c);
            if (comp2 != null)
                return comp2;
        }/*from   w w w .java  2  s  . co  m*/
    }
    return null;
}

From source file:Main.java

/**
 * Forces an immediate repaint of a component and all of its children.
 *
 * @param component//from  w ww .j a  v a  2 s .c om
 */
public static void paintImmediately(Component component) {

    // Paint the component
    if (component instanceof JComponent) {
        JComponent jcomponent = (JComponent) component;
        jcomponent.paintImmediately(jcomponent.getBounds());
    }

    // Recursively paint children
    if (component instanceof Container) {
        Container container = (Container) component;
        int numberOfChildren = container.getComponentCount();
        for (int i = 0; i < numberOfChildren; i++) {
            Component child = container.getComponent(i);
            paintImmediately(child);
        }
    }
}