Java tutorial
//package com.java2s; import javax.swing.*; public class Main { /** * Convenience method to obtain the Swing class from which this * component was directly or indirectly derived. * * @param component The component whose Swing superclass is to be * determined * @return The nearest Swing class in the inheritance tree */ public static <T extends JComponent> Class getJClass(T component) { Class<?> clazz = component.getClass(); while (!clazz.getName().matches("javax.swing.J[^.]*$")) { clazz = clazz.getSuperclass(); } return clazz; } }