Java JFrame Parent enableAllComponentsExcept(final boolean enable, final Frame parent, final Component... components)

Here you can find the source of enableAllComponentsExcept(final boolean enable, final Frame 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 Frame 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 w  ww. j  a v  a  2  s.  c  o  m
     * 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. centreOverFrame(JInternalFrame win, JInternalFrame parent)
  2. closeFrameWhenEscapePressed(final JRootPane panel, final ActionListener actListener)
  3. createExceptionDialog(Frame parent, String title, Throwable error)
  4. createProgressDialog(Frame parentFrame, String title, JProgressBar progressBar)
  5. enableAllComponents(final boolean enable, final Frame parent)
  6. ensureVisibilityAtParent(final JInternalFrame frame)
  7. execLoop(JComponent editor, Frame parent, boolean modal, int w, int h)
  8. fileOpen(Frame parent, String typename, String ext)
  9. findParentDialogOrFrame(Container container)