Example usage for javax.swing JComponent getComponents

List of usage examples for javax.swing JComponent getComponents

Introduction

In this page you can find the example usage for javax.swing JComponent getComponents.

Prototype

public Component[] getComponents() 

Source Link

Document

Gets all the components in this container.

Usage

From source file:Main.java

/**
 * recursive implementation/* ww  w. ja  va2s  . c  o m*/
 * @param value
 * @param c
 */
public static void enable(JComponent c, boolean value) {
    Component comp[] = c.getComponents();
    for (int i = 0; i < comp.length; i++) {
        comp[i].setEnabled(value);
        if (comp[i] instanceof JComponent) {
            enable((JComponent) comp[i], value);
        }
    }
}

From source file:Main.java

public static void removeMouseListenerToHierarchy(JComponent c, MouseListener listener) {
    for (Component comp : c.getComponents()) {
        comp.removeMouseListener(listener);

        if (comp instanceof JComponent) {
            removeMouseListenerToHierarchy((JComponent) comp, listener);
        }// w ww .  j  a v  a 2 s  .c o m
    }
}

From source file:Main.java

public static void addMouseListenerToHierarchy(JComponent c, MouseListener listener) {
    for (Component comp : c.getComponents()) {
        comp.addMouseListener(listener);

        if (comp instanceof JComponent) {
            addMouseListenerToHierarchy((JComponent) comp, listener);
        }/*ww w . j  a  v a2  s  . co m*/
    }
}

From source file:Main.java

/**
 * Recursive method to disable all child components in JComponent
 * @param component the highest level parent component
 * @return The original state of all the child components
 *///from w  ww  .  j  a v a2  s.co  m
public static Map<Component, Boolean> disableAllChildComponents(JComponent... components) {
    Map<Component, Boolean> stateMap = new HashMap<Component, Boolean>();

    for (JComponent component : components) {
        for (Component child : component.getComponents()) {
            stateMap.put(child, child.isEnabled());
            child.setEnabled(false);
            if (child instanceof JComponent)
                stateMap.putAll(disableAllChildComponents((JComponent) child));
        }
    }

    return stateMap;
}

From source file:Main.java

public static void showAsOnlyVisibleChild(JComponent container, Component childToBeMadeVisible) {
    for (Component child : container.getComponents()) {
        boolean visible = child.equals(childToBeMadeVisible);
        child.setVisible(visible);/*from   w w  w.  j a  v  a  2  s  .c  o  m*/
        if (visible) {
            container.getLayout().addLayoutComponent(BorderLayout.CENTER, child);
        } else {
            container.getLayout().removeLayoutComponent(child);
        }
        child.repaint();
    }
    container.revalidate();
    container.repaint();
}

From source file:Main.java

public static void setJComponentEnabled(JComponent component, boolean enabled) {
    component.setEnabled(enabled);// w w w.jav  a2s.co  m
    for (Component c : component.getComponents()) {
        c.setEnabled(enabled);
    }
}

From source file:Main.java

/** Recursively sets or clears the enabled property on a JComponent and all its children. */
public static void setEnabledRecursive(JComponent c, boolean enabled) {
    c.setEnabled(enabled);/* www  . ja  v a  2s.c  o  m*/
    Component[] child = c.getComponents();
    for (int i = 0; i < child.length; ++i) {
        if (child[i] instanceof JComponent)
            setEnabledRecursive((JComponent) child[i], enabled);
    }
}

From source file:Main.java

public static void setEnabled(JComponent component, boolean t) {
    synchronized (component.getTreeLock()) {
        for (Component c : component.getComponents())
            if (c instanceof JComponent)
                setEnabled((JComponent) c, t);
    }//from  w  ww  .j a va  2  s  .  co  m
    component.setEnabled(t);
}

From source file:Main.java

/**
 * Remove all the opaqueness of the given components and child components.
 * /* ww w  . j av a2s  . c o  m*/
 * @param components list of components
 */
public static void removeOpaqueness(Component... components) {
    for (Component component : components) {
        if (component instanceof JComponent) {
            JComponent jComponent = (JComponent) component;
            jComponent.setOpaque(false);
            removeOpaqueness(jComponent.getComponents());
        }
    }
}

From source file:Main.java

public static JComponent match(JComponent c, final String name) {
    if (c.getName() != null && c.getName().contains(name))
        return c;
    for (Component ci : c.getComponents()) {
        if (ci instanceof JComponent) {
            JComponent ret = match((JComponent) ci, name);
            if (ret != null)
                return ret;
        }//from   w  w w .  j av a2 s  .com
    }
    return null;
}