The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.awt  [78 examples] > Containers  [3 examples]

e572. Getting the Child Components of a Container

This example retrieves all of a container's children in an array:
    // Get children
    Component[] components = container.getComponents();
    
    for (int i=0; i<components.length; i++) {
        // Get the component's bounds
        Rectangle bounds = components[i].getBounds();
    }
This example retrieves all components individually:
    // Get number of children
    int count = container.getComponentCount();
    
    for (int i=0; i<count; i++) {
        Component c = container.getComponent(i);
    }

 Related Examples
e571. Creating a Container
e573. Determining When a Component Is Added or Removed from a Container

See also: Colors    Components    Cursors    Drawing    Events    Focus    Frames    GridBagLayout    Images    Shapes    Simulating Events    Text    The Screen   


© 2002 Addison-Wesley.