Example usage for java.awt Component setEnabled

List of usage examples for java.awt Component setEnabled

Introduction

In this page you can find the example usage for java.awt Component setEnabled.

Prototype

public void setEnabled(boolean b) 

Source Link

Document

Enables or disables this component, depending on the value of the parameter b .

Usage

From source file:Main.java

/**
 * Enables specified components./*from  w w w.  j  a v a 2s  .c  o  m*/
 *
 * @param disabled disabled components list
 */
public static void enable(final List<Component> disabled) {
    for (final Component component : disabled) {
        component.setEnabled(true);
    }
}

From source file:Main.java

/**
 * Enables or disables of the components in the tree starting with {@code c}.
 * /* ww w. j  a  v  a 2  s . co m*/
 * @param c
 *                the starting component
 * @param enabled
 *                {@code true} if the component is to enabled; {@code false} otherwise
 */
public static void setComponentTreeEnabled(Component c, boolean enabled) {
    c.setEnabled(enabled);

    Component[] children = getChildren(c);

    if (children != null) {
        for (int i = 0; i < children.length; i++) {
            setComponentTreeEnabled(children[i], enabled);
        }
    }
}

From source file:Main.java

static void setDescendantsEnabled(final Component component, final boolean enabled) {
    if (component != null) {
        component.setEnabled(enabled);
        if (component instanceof Container) {
            final Container container = (Container) component;
            for (final Component child : container.getComponents()) {
                setDescendantsEnabled(child, enabled);
            }//  www  . j  a  v a2  s.  com
        }
    }
}

From source file:Main.java

/**
 * Enables or disables all children of the given container.
 *
 * @param container the container//from   w  w w .jav  a  2 s  .co  m
 * @param enable if true, the components are enabled, otherwise they are disabled
 */
public static void enableContainerChildren(Container container, boolean enable) {
    if (container == null)
        return;
    for (Component comp : container.getComponents()) {
        try {
            comp.setEnabled(enable);
            ((JComponent) comp).setOpaque(enable);
            if (comp instanceof Container)
                enableContainerChildren((Container) comp, enable);
        } catch (ClassCastException e) {
            // ignore component
            continue;
        }
    }
}

From source file:Main.java

/**
 * Thread-friendly wrapper method for <code>Component.setEnabled</code>.
 * @param enable//w w  w  .ja  v  a2 s  .  c  o m
 * @param components
 * @deprecated
 */
@Deprecated
public static void setEnabled(final boolean enable, final Component... components) {
    Runnable r = new Runnable() {

        public void run() {
            for (Component comp : components) {
                comp.setEnabled(enable);
            }
        }
    };

    if (EventQueue.isDispatchThread()) {
        r.run();
        return;
    }

    runTask(r, true);
}

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
 *//*  w  w w  .  j a  va 2 s  . c o  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

/**
 * Sets enabled state of component and all of its children.
 *
 * @param component//from w w w  .ja  v a  2  s. com
 *            component to modify
 * @param enabled
 *            whether component is enabled or not
 * @param startFromChilds
 *            whether exclude component from changes or not
 */
public static void setEnabledRecursively(final Component component, final boolean enabled,
        final boolean startFromChilds) {
    if (component == null) {
        return;
    }
    if (!startFromChilds) {
        component.setEnabled(enabled);
    }
    if (component instanceof Container) {
        if (!startFromChilds && isHandlesEnableState(component)) {
            return;
        }
        for (final Component child : ((Container) component).getComponents()) {
            setEnabledRecursively(child, enabled, false);
        }
    }
}

From source file:Main.java

public static void enableChildren(JPanel panel, Class<?>... classesToIgnore) {
    for (Component component : panel.getComponents()) {
        if (component instanceof JPanel) {
            enableChildren((JPanel) component, classesToIgnore);
        } else {/*from w ww  .  j a va2  s .  co  m*/
            if (!ignoreClasses(component, classesToIgnore)) {
                component.setEnabled(true);
            }
        }
    }
}

From source file:Main.java

public static void disableChildren(JPanel panel, Class<?>... classesToIgnore) {
    for (Component component : panel.getComponents()) {
        if (component instanceof JPanel) {
            disableChildren((JPanel) component, classesToIgnore);
        } else {/*from  w  ww  . java  2 s .  co  m*/
            if (!ignoreClasses(component, classesToIgnore)) {
                component.setEnabled(false);
            }
        }
    }
}

From source file:AWTUtilities.java

/**
 * Enables or disables all the components within the specified container.
 * /*from ww  w  .jav  a 2s . c o  m*/
 * This is a rather hacky method - it doesn't work well if there are both
 * enabled and disabled components in the container.
 */

public static void setContainerEnabled(Container container, boolean enabled) {
    Component[] children = container.getComponents();
    for (int i = 0; i < children.length; i++) {
        Component child = children[i];
        child.setEnabled(enabled);
        if (child instanceof Container)
            setContainerEnabled((Container) child, enabled);
    }
}