Java JComponent Container getComponent(JComponent container, String name)

Here you can find the source of getComponent(JComponent container, String name)

Description

get Component

License

Open Source License

Declaration

public static JComponent getComponent(JComponent container, String name) 

Method Source Code

//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;
    }
}

Related

  1. getAncestorsOfClass(JComponent start, Class theClass)
  2. getBooleanClientProperty(JComponent c, Object property)
  3. getChildJComponents(Container container)
  4. getClipboard(JComponent c)
  5. getComponent(JComponent container, String name)
  6. getComponentByName(boolean enableDeepSearch, JComponent rootComponent, String name)
  7. getComponentsOfType(JComponent base, Class type)
  8. getComponentState(JComponent c)
  9. getDataFlavors(JComponent component)