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:JRadioButtonSelectedElements.java

public static Enumeration<String> getSelectedElements(Container container) {
    Vector<String> selections = new Vector<String>();
    Component components[] = container.getComponents();
    for (int i = 0, n = components.length; i < n; i++) {
        if (components[i] instanceof AbstractButton) {
            AbstractButton button = (AbstractButton) components[i];
            if (button.isSelected()) {
                selections.addElement(button.getText());
            }//from  w  w  w.j  a va2  s  .co m
        }
    }
    return selections.elements();
}

From source file:Main.java

/**
 * Sets the cursor for the given component and all child components to the
 * given cursor./*w w w .  j a  v a  2  s.  c  o  m*/
 */
public static void setCursor(final Component c, final Cursor cursor) {
    if (c == null)
        return;
    c.setCursor(cursor);
    if (c instanceof JFrame)
        setCursor(((JFrame) c).getContentPane(), cursor);
    else if (c instanceof JDialog) {
        setCursor(((JDialog) c).getContentPane(), cursor);
    } else if (c instanceof Container) {
        final Container contain = (Container) c;
        final Component[] sub = contain.getComponents();
        for (int i = 0; i < sub.length; i++)
            setCursor(sub[i], cursor);
    }
}

From source file:Main.java

/**
 * Returns all the components (and their children) associated to the given container.
 *
 * @param container Container/*  ww w  .j  a v  a 2  s.co m*/
 * @return {@code Component} list
 * @since 0.3.0
 */
public static List<Component> getAllComponents(Container container) {
    List<Component> out = new LinkedList<Component>();
    for (Component comp : container.getComponents()) {
        out.add(comp);
        if (comp instanceof Container)
            out.addAll(getAllComponents((Container) comp));
    }

    return out;
}

From source file:Main.java

public static JComponent[] getAllSubComponents(Container root) {
    List<JComponent> comps = new LinkedList<JComponent>();
    for (Component c : root.getComponents()) {
        try {//from  ww  w.  ja va 2 s  .co  m
            comps.add((JComponent) c);
            comps.addAll(Arrays.asList(getAllSubComponents((JComponent) c)));
        } catch (final ClassCastException e) {
            continue;
        }
    }
    return comps.toArray(new JComponent[comps.size()]);
}

From source file:Main.java

private static JButton getButtonSubComponent(Container container) {
    if (container instanceof JButton) {
        return (JButton) container;
    } else {//from  w  w  w  .j  av a  2  s .c o  m
        Component[] components = container.getComponents();
        for (Component component : components) {
            if (component instanceof Container) {
                return getButtonSubComponent((Container) component);
            }
        }
    }
    return null;
}

From source file:Main.java

public static void validateTree(java.awt.Component c) {
    c.validate();//from   ww  w. j  a va2 s.c  o m
    if (c instanceof java.awt.Container) {
        java.awt.Container container = (java.awt.Container) c;
        for (java.awt.Component component : container.getComponents()) {
            validateTree(component);
        }
    }
}

From source file:Main.java

public static void setSizeToPreferredSizeTree(java.awt.Component c) {
    if (c instanceof java.awt.Container) {
        java.awt.Container container = (java.awt.Container) c;
        for (java.awt.Component component : container.getComponents()) {
            setSizeToPreferredSizeTree(component);
        }//from w w  w. ja  v  a  2 s . c  o m
    }
    c.setSize(c.getPreferredSize());
}

From source file:Main.java

public static void invalidateTree(java.awt.Component c) {
    c.invalidate();//w  ww  .j  a v a 2 s.  co m
    if (c instanceof java.awt.Container) {
        java.awt.Container container = (java.awt.Container) c;
        for (java.awt.Component component : container.getComponents()) {
            invalidateTree(component);
        }
    }
}

From source file:Main.java

public static void doLayoutTree(java.awt.Component c) {
    //c.doLayout();
    if (c instanceof java.awt.Container) {
        java.awt.Container container = (java.awt.Container) c;
        for (java.awt.Component component : container.getComponents()) {
            doLayoutTree(component);/*w  w w.j av  a  2  s .c om*/
        }
    }
    c.doLayout();
}

From source file:Main.java

public static void revalidateTree(java.awt.Component c) {
    if (c instanceof javax.swing.JComponent) {
        javax.swing.JComponent jc = (javax.swing.JComponent) c;
        jc.revalidate();/*from  ww w  . j a  v  a  2s . co m*/
    }
    if (c instanceof java.awt.Container) {
        java.awt.Container container = (java.awt.Container) c;
        for (java.awt.Component component : container.getComponents()) {
            revalidateTree(component);
        }
    }
}