Java tutorial
//package com.java2s; import java.awt.Component; import javax.swing.JPanel; public class Main { public static void disableChildren(JPanel panel, Class<?>... classesToIgnore) { for (Component component : panel.getComponents()) { if (component instanceof JPanel) { disableChildren((JPanel) component, classesToIgnore); } else { if (!ignoreClasses(component, classesToIgnore)) { component.setEnabled(false); } } } } private static boolean ignoreClasses(Object o, Class<?>... classes) { if (classes != null) { for (Class<?> c : classes) { if (ignoreClass(o, c)) return true; } } return false; } private static boolean ignoreClass(Object o, Class<?> c) { return c.isAssignableFrom(o.getClass()); } }