Java tutorial
//package com.java2s; import java.awt.Component; import java.awt.Container; import java.util.HashMap; public class Main { public static HashMap createComponentMap(Container ParentComponent) { // recursive add all sub-coponents into hashmap HashMap ComponentMap = new HashMap<String, Component>(); Component[] components = ParentComponent.getComponents(); for (Component comp : components) { if (comp instanceof Container) { ComponentMap.putAll(createComponentMap((Container) comp)); } for (int i = 0; i < components.length; i++) { ComponentMap.put(components[i].getName(), components[i]); } } return ComponentMap; } }