Example usage for java.awt Container getComponent

List of usage examples for java.awt Container getComponent

Introduction

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

Prototype

public Component getComponent(int n) 

Source Link

Document

Gets the nth component in this container.

Usage

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;/*from www .  ja  va2 s .  c  o m*/
        }
    }
    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   www.j a  v a 2s.  c om
        }
    }
    return height;
}

From source file:Util.java

public static int countComponents(Container c) {
    int num = 1;/*w  w w.j a v a  2  s .  c  om*/
    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: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;
        }/*from www .j ava 2  s . c  om*/
    }

    return -1;
}

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;
        }/*from www  . ja  v  a 2 s . c o m*/
    }
    return -1;
}

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.  ja v a 2 s. co m
        container.removeAll();
    }
}

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;
        }/* w  w  w . jav a 2s .c  om*/
    }
    return null;
}

From source file:Main.java

public static Component getChild(Component parent, String name) {
    parent = getContainer(parent);/*w  w w . j  ava2  s  .  c  om*/

    if (parent instanceof JSplitPane) {
        JSplitPane split = (JSplitPane) parent;
        if (JSplitPane.TOP.equals(name)) {
            return split.getTopComponent();
        } else if (JSplitPane.LEFT.equals(name)) {
            return split.getLeftComponent();
        } else if (JSplitPane.RIGHT.equals(name)) {
            return split.getRightComponent();
        } else if (JSplitPane.BOTTOM.equals(name)) {
            return split.getBottomComponent();
        }
    }
    Container cont = (Container) parent;
    for (int i = 0; i < cont.getComponentCount(); i++) {
        Component comp = cont.getComponent(i);
        if (name.equals(comp.getName())) {
            return comp;
        }
    }
    if (name.endsWith(VIEW_SUFFIX)) {
        String subName = name.substring(0, name.length() - VIEW_SUFFIX.length());
        if (subName.isEmpty()) {
            return parent;
        }
        return getContainer(getChild(parent, subName));
    }

    throw new IllegalArgumentException("No component named " + name);
}

From source file:Main.java

static public <T> void findDescentdantsOfType(List<T> holder, Container acomp, Class<T> type) {
    if (type.isInstance(acomp))
        holder.add((T) acomp);/*from  www.  java2  s .co m*/
    for (int i = 0; i < acomp.getComponentCount(); i++) {
        Component child = acomp.getComponent(i);
        if (child instanceof Container) {
            findDescentdantsOfType(holder, (Container) child, type);
        }
    }
}

From source file:Main.java

public static void addKeyAdapterRecursively(final Container container, final KeyAdapter keyAdapter) {
    container.addKeyListener(keyAdapter);
    for (int i = 0; i < container.getComponentCount(); i++) {
        final Component child = container.getComponent(i);
        if (child instanceof Container) {
            addKeyAdapterRecursively((Container) child, keyAdapter);
        }// w  ww .j  a v  a  2 s. c om
        child.addKeyListener(keyAdapter);
    }
}