set Components Enabled - Java Swing

Java examples for Swing:JComponent

Description

set Components Enabled

Demo Code


//package com.java2s;

import java.awt.Component;
import java.awt.Container;

import javax.swing.AbstractButton;

import javax.swing.JComboBox;

import javax.swing.JTabbedPane;

import javax.swing.text.JTextComponent;

public class Main {
    public static void setComponentsEnabled(Container c, boolean flag) {
        setComponentsEnabled(c, flag, false);
    }//from   w w w  .ja v a 2 s. c o m

    public static void setComponentsEnabled(Container c, boolean flag,
            boolean recursive) {
        Component[] components = c.getComponents();
        for (Component comp : components) {
            if (comp instanceof AbstractButton
                    || comp instanceof JTextComponent
                    || comp instanceof JComboBox
                    || comp instanceof JTabbedPane)
                comp.setEnabled(flag);
            if (recursive && comp instanceof Container)
                setComponentsEnabled((Container) comp, flag, recursive);
        }
    }
}

Related Tutorials