Package java.awt |
![]() Previous |
![]() Java API |
![]() Index |
![]() Next |
public abstract class java.awt.Container extends java.awt.Component { // Methods public Component add(Component comp); public Component add(Component comp, int pos); public Component add(String name, Component comp); public void addNotify(); public int countComponents(); public void deliverEvent(Event evt); public Component getComponent(int n); public Component[] getComponents(); public LayoutManager getLayout(); public Insets insets(); public void layout(); public void list(PrintStream out, int indent); public Component locate(int x, int y); public Dimension minimumSize(); public void paintComponents(Graphics g); protected String paramString(); public Dimension preferredSize(); public void printComponents(Graphics g); public void remove(Component comp); public void removeAll(); public void removeNotify(); public void setLayout(LayoutManager mgr); public void validate(); }
Container is the abstract superclass representing all components that can hold other components.
Each container may be associated with a LayoutManager instance that determines the position of each of the container's subcomponents.
public Component add(Component comp)Adds the specified component to the end of this container.
Return Value:
Returns the component argument.
Parameter Description comp the component to be added
public Component add(Component comp, int pos)Adds the specified component to this container at the given position.
Return Value:
Returns the component argument.
Parameter Description comp the component to be added pos the position at which to insert the component; or -1 to insert at the end See Also: remove .
public Component add(String name, Component comp)Adds the specified component to the end of this container. Also add the component to the layout manager using the name specified.
Return Value:
Returns the component argument.
Parameter Description name a tag understood by the layout manager comp the component to be added See Also: remove LayoutManager .
public void addNotify()Notifies this container to create a peer.
The addNotify method of Container calls the addNotify method for each of the components in this container. It then calls its superclass's addNotify method , to indicate that the container needs to be laid out again since its size may have changed.
Most applications do not call this method directly.
Overrides:
addNotify in class Component .
See Also: removeNotify .
public int countComponents()Return Value:
Returns the number of components in this container.
See Also: getComponent .
public void deliverEvent(Event evt)Delivers an event to this component or one of its subcomponents.
The deliverEvent method of Container determines whether this event properly belongs to one of its subcomponents. If so, it translates the event into the subcomponent's coordinate system and delivers the event to it by calling its deliverEvent method .
If the event doesn't properly belong to one of the container's subcomponents, it calls this container's postEvent method on the event.
Parameter Description evt the event Overrides:
deliverEvent in class Component .
See Also: handleEvent in class Component .
public Component getComponent(int n)Return Value:
Returns the nth component in this container.
Parameter Description n the index of the component to get Throw:
ArrayIndexOutOfBoundsException
If the nth value does not exist.
public Component[] getComponents()Return Value:
Returns an array of all the component in this container.
public LayoutManager getLayout()Return Value:
Returns the layout manager for this container.
public Insets insets()Determines the insets of this container, which indicate the size of the container's border.
A Frame, for example, has a top inset that corresponds to the height of the frame's title bar.
The insets method of Container calls the insets method of this container's peer, if the container has a peer. Otherwise it returns the inset new Inset(0, 0, 0, 0), which indicates that the container has no border.
Return Value:
Returns the insets of this container
See Also: LayoutManager .
public void layout()Lays out this container.
The layout method of Container calls the layoutContainer method of the container's layout manager.
Most applications do not call this method directly. This method is called when a container calls its validate method .
Overrides:
layout in class Component .
See Also: setLayout .
public void list(PrintStream out, int indent)Prints a listing of this container to the specified output stream. The listing starts at the specified indentation.
The list method of Container prints itself by calling its superclass's list method and then calls list on each of its subcomponents with and indentation of indent + 1.
Parameter Description out a print stream indent the number of spaces to indent Overrides:
list in class Component .
public Component locate(int x, int y)Determines the component or subcomponent of this container that contains the (x,y) coordinate. This method only looks one level deep. If the point (x,y) is inside a subcomponent that itself has subcomponents, it does not go looking down the subcomponent tree.
The locate method of Container first determines if the (x,y) coordinate is inside its own boundaries. If not, it returns null immediately. If the coordinate is inside its boundaries, it calls inside on each of the subcomponents; if any of those calls to returns true, that subcomponent is returned; otherwise the container target object is returned.
Return Value:
Returns this container or one of its subcomponent that contains the (x,y) coordinate; null if the coordinate is outside this container.
Parameter Description x the x coordinate y the y coordinate Overrides:
locate in class Component .
public Dimension minimumSize()Determines the minimum size of this container.
The minimumSize method of Container checks to see if this container has a layout manager . If so, its minimumLayoutSize method is called. Otherwise, its superclass's minimumSize method is called.
Return Value:
Returns the minimum size of this container.
Overrides:
minimumSize in class Component .
See Also: preferredSize .
public void paintComponents(Graphics g)Paints each of the components in th is container.
Parameter Description g the graphics context See Also: paint in class Component paintAll in class Component .
protected String paramString()Returns the parameter string representing the state of this container. This string is useful for debugging.
Return Value:
Returns the parameter string of this container.
Overrides:
paramString in class Component .
public Dimension preferredSize()Determines the preferred size of this container.
The preferredSize method of Container checks to see if this container has a layout manager . If so, its preferredLayoutSize method is called. Otherwise, its superclass's preferredSize method is called.
Return Value:
Returns the minimum size of this container.
Overrides:
preferredSize in class Component .
See Also: minimumSize .
public void printComponents(Graphics g)Prints each of the components in this container.
Parameter Description g the graphics context See Also: print in class Component printAll in class Component .
public void remove(Component comp)Removes the specified component from this container. This method also causes the component to call its removeNotify method to remove its peer.
Parameter Description comp the component to be removed See Also: add .
public void removeAll()Removes all the components from this container. This method also causes all the components in the container to call their removeNotify method to remove their peers.
public void removeNotify()Notifies this container and all its subcomponents to destroy their peers.
Overrides:
removeNotify in class Component .
See Also: addNotify .
public void setLayout(LayoutManager mgr)Sets the layout manager for this container.
Parameter Description mgr the new layout manager
public void validate()Validates this container and all of its subcomponents. The AWT uses this method to have a container be laid out again after adding or otherwise changing the components it contains.
Overrides:
validate in class Component .
See Also: invalidate in class Component .