disable Components inside java.awt.Container - Java java.awt

Java examples for java.awt:Component

Description

disable Components inside java.awt.Container

Demo Code


//package com.java2s;

import javax.swing.*;

import java.awt.*;

public class Main {

    public static void disableComponents(java.awt.Container c) {
        Component[] components = c.getComponents();
        for (Component comp : components) {
            if (comp instanceof JScrollPane)
                continue;
            if (comp instanceof java.awt.Container)
                disableComponents((java.awt.Container) comp);
            comp.setEnabled(false);/*from   w w  w .  j  a  v a2s  .c  o m*/
        }
    }
}

Related Tutorials