Java tutorial
//package com.java2s; import java.awt.Component; import java.lang.reflect.Method; import javax.swing.JPanel; public class Main { public static void rwChildren(JPanel panel, Class<?>... classesToIgnore) { for (Component component : panel.getComponents()) { if (component instanceof JPanel) { rwChildren((JPanel) component, classesToIgnore); } else { if (!ignoreClasses(component, classesToIgnore)) { Method m = discover(component, "setEditable", boolean.class); invoke(m, component, new Object[] { Boolean.TRUE }); } } } } private static boolean ignoreClasses(Object o, Class<?>... classes) { if (classes != null) { for (Class<?> c : classes) { if (ignoreClass(o, c)) return true; } } return false; } public static Method discover(Object o, String method, Class<?> signature) { Method m = null; try { m = o.getClass().getMethod(method, signature); } catch (Exception ignore) { } return m; } public static void invoke(Method m, Object o, Object[] signature) { if (m == null) return; try { m.invoke(o, signature); } catch (Exception ignore) { } } private static boolean ignoreClass(Object o, Class<?> c) { return c.isAssignableFrom(o.getClass()); } }