Here you can find the source of getComponent(JComponent container, String name)
public static JComponent getComponent(JComponent container, String name)
//package com.java2s; /*//from ww w .j av a2 s. c o m * Copyright (c) 2014 tabletoptool.com team. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Public License v3.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/gpl.html * * Contributors: * rptools.com team - initial implementation * tabletoptool.com team - further development */ import java.awt.Component; import java.awt.Container; import java.util.LinkedList; import java.util.List; import javax.swing.JComponent; public class Main { public static JComponent getComponent(JComponent container, String name) { List<Component> componentQueue = new LinkedList<Component>(); componentQueue.add(container); while (componentQueue.size() > 0) { Component c = componentQueue.remove(0); String cname = c.getName(); if (cname != null && cname.equals(name)) { return (JComponent) c; } if (c instanceof Container) { for (Component child : ((Container) c).getComponents()) { componentQueue.add(child); } } } return null; } }