Java tutorial
//package com.java2s; import java.awt.Component; import java.awt.Container; import java.util.ArrayList; import java.util.List; public class Main { static public <T> List<T> findDescentdantsOfType(Container acomp, Class<T> type) { List<T> holder = new ArrayList<T>(); findDescentdantsOfType(holder, acomp, type); return holder; } static public <T> void findDescentdantsOfType(List<T> holder, Container acomp, Class<T> type) { if (type.isInstance(acomp)) holder.add((T) acomp); for (int i = 0; i < acomp.getComponentCount(); i++) { Component child = acomp.getComponent(i); if (child instanceof Container) { findDescentdantsOfType(holder, (Container) child, type); } } } }