Enumerating all components in a container

You can use (potentially recursively) the getComponents() method to find the component you want to test:

    private static void listComponents(Container container) {
        Component[] components = container.getComponents();
        for (int i = 0; i < components.length; i++) {
            System.out.println(components[i]);
            if (components[i] instanceof Container) {
                listComponents((Container) components[i]);
            }
        }
    }

Previous | Next | Top | Cafe con Leche

Copyright 2005 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified August 11, 2005