Class (Class<?> componentClass) { while (true) { componentClass = componentClass.getSuperclass(); if (componentClass.equals(JComponent.class)) { return JPanel.class; } if ((componentClass.getModifiers() & (Modifier.ABSTRACT | Modifier.PRIVATE)) != 0) { continue; } try { componentClass.getConstructor(); } catch (NoSuchMethodException ex) { continue; } return componentClass; } }