Java tutorial
//package com.java2s; /* * Copyright 2001-2008 Aqris Software AS. All rights reserved. * * This program is dual-licensed under both the Common Development * and Distribution License ("CDDL") and the GNU General Public * License ("GPL"). You may elect to use one or the other of these * licenses. */ import javax.swing.JComponent; import java.awt.Component; import java.awt.Container; import java.util.ArrayList; import java.util.List; public class Main { public static List getChildJComponents(Container container) { List result = new ArrayList(); Component[] children = container.getComponents(); for (int i = 0; i < children.length; i++) { if (children[i] instanceof JComponent) { result.add(children[i]); result.addAll(getChildJComponents((JComponent) children[i])); } } return result; } }