Java tutorial
//package com.java2s; import java.awt.*; import javax.swing.*; public class Main { public static Component getFirstChildComponent(Container container, Class ofType) { java.awt.Component[] comps = container.getComponents(); Component comp = null; for (int n = 0; n < comps.length; n++) { System.out.println("WHat component am I " + n + ":" + comps[n] + " IN " + container); if (ofType.isInstance(comps[n])) return comps[n]; if (comps[n] instanceof JComponent || comps[n] instanceof Container) comp = getFirstChildComponent((Container) comps[n], ofType); if (comp != null) { // Does this component have the focus? boolean hasFocus = comp.hasFocus(); if (hasFocus) return comp; } } return null; } }