Java JDialog enableAllComponentsExcept(final boolean enable, final JDialog parent, final Component... components)

Here you can find the source of enableAllComponentsExcept(final boolean enable, final JDialog parent, final Component... components)

Description

Enables/Disables all the components of a Frame except the specified components based on the input.

License

Open Source License

Parameter

Parameter Description
enable a parameter
parent a parameter
components a parameter

Declaration

public static void enableAllComponentsExcept(final boolean enable, final JDialog parent,
        final Component... components) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.Component;

import java.awt.Frame;

import java.util.Arrays;
import javax.swing.JDialog;

public class Main {
    /**/*from   ww  w  .  j  ava 2 s.c  om*/
     * Enables/Disables all the components of a Frame except the specified components based on the
     * input.
     *
     * @param enable
     * @param parent
     * @param components
     */
    public static void enableAllComponentsExcept(final boolean enable, final Frame parent,
            final Component... components) {
        if (null != parent) {
            Component[] allComponents = parent.getComponents();
            if (null == allComponents) {
                return;
            }
            if (allComponents.length <= 0) {
                return;
            }
            for (Component component : allComponents) {
                if (null != component && components != null) {
                    if (contains(component, components)) {
                        continue;
                    }
                    component.setEnabled(enable);
                }
            }
        }
    }

    /**
     * Enables/Disables all the components of a Frame except the specified components based on the
     * input.
     *
     * @param enable
     * @param parent
     * @param components
     */
    public static void enableAllComponentsExcept(final boolean enable, final JDialog parent,
            final Component... components) {
        if (null != parent) {
            Component[] allComponents = parent.getRootPane().getComponents();
            if (null == allComponents) {
                return;
            }
            if (allComponents.length <= 0) {
                return;
            }
            for (Component component : allComponents) {
                if (null != component && components != null) {
                    if (contains(component, components)) {
                        continue;
                    }
                    component.setEnabled(enable);
                }
            }
        }
    }

    /**
     * 
     * @param item
     * @param items
     * @return
     */
    public static <T> boolean contains(T item, T... items) {
        if (null == item || null == items) {
            return false;
        }
        if (items.length <= 0) {
            return false;
        }
        return Arrays.asList(items).contains(item);
    }
}

Related

  1. configureCancelForDialog(final JDialog dialog, JButton cancelButton)
  2. decorate(JDialog dialog, int type)
  3. displayInDialog(JComponent comp, JDialog result)
  4. disposeOnClose(javax.swing.JDialog d)
  5. enableAllComponents(final boolean enable, final JDialog parent)
  6. endTask(javax.swing.JDialog jp)
  7. findJDialog(Component c)
  8. fit(JDialog d)
  9. getJDialog(JComponent c)