Java tutorial
//package com.java2s; import java.awt.*; import java.util.*; public class Main { protected static void fillAllDescendants(Container c, Class findClass, boolean deep, Collection results) { if (findClass.isInstance(c)) { results.add(c); if (!deep) return; } for (int i = 0; i < c.getComponentCount(); i++) { Component comp = c.getComponent(i); if (comp instanceof Container) fillAllDescendants((Container) comp, findClass, deep, results); } } }