Packages  This Package  Prev  Next  Index  

§1.11 Class Container

public  abstract  class  java.awt.Container
    extends  java.awt.Component  (II-§1.10)
{
        // Methods
    public Component add(Component  comp);	§1.11.1
    public Component add(Component  comp, int  pos);	§1.11.2
    public Component add(String  name, Component  comp);	§1.11.3
    public void addNotify();	§1.11.4
    public int countComponents();	§1.11.5
    public void deliverEvent(Event  evt);	§1.11.6
    public Component getComponent(int  n);	§1.11.7
    public Component[] getComponents();	§1.11.8
    public LayoutManager getLayout();	§1.11.9
    public Insets insets();	§1.11.10
    public void layout();	§1.11.11
    public void  list(PrintStream  out, int  indent);	§1.11.12
    public Component locate(int  x, int  y);	§1.11.13
    public Dimension minimumSize();	§1.11.14
    public void paintComponents(Graphics  g);	§1.11.15
    protected String paramString();	§1.11.16
    public Dimension preferredSize();	§1.11.17
    public void printComponents(Graphics  g);	§1.11.18
    public void remove(Component  comp);	§1.11.19
    public void removeAll();	§1.11.20
    public void removeNotify();	§1.11.21
    public void setLayout(LayoutManager  mgr);	§1.11.22
    public void validate();	§1.11.23
}
Container is the abstract superclass representing all components that can hold other components.

Each container may be associated with a LayoutManager instance (II-§1.43) that determines the position of each of the container's subcomponents.


Methods

add

public Component add(Component comp)
Adds the specified component to the end of this container.
Parameters:
comp - the component to be added
Returns:
the component argument.

add

public Component add(Component comp, int pos)
Adds the specified component to this container at the given position.
Parameters:
comp - the component to be added
pos - the position at which to insert the component; or -1 to insert at the end
Returns:
the component argument.
See Also:
remove (II-§1.11.19).

add

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.
Parameters:
name - a tag understood by the layout manager
comp - the component to be added
Returns:
the component argument.
See Also:
remove (II-§1.11.19)
LayoutManager (II-§1.43).

addNotify

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 (II-§1.10.2), 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 (II-§1.10.2).
See Also:
removeNotify (II-§1.11.21).

countComponents

public int countComponents()
Returns:
the number of components in this container.
See Also:
getComponent (II-§1.11.6).

deliverEvent

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 (II-§1.10.8).


If the event doesn't properly belong to one of the container's subcomponents, it calls this container's postEvent method (II-§1.10.52) on the event.

Parameters:
evt - the event
Overrides:
deliverEvent in class Component (II-§1.10.8).
See Also:
handleEvent in class Component (II-§1.10.22).

getComponent

public Component getComponent(int n)
Parameters:
n - the index of the component to get
Returns:
the nth component in this container.
Throws
ArrayIndexOutOfBoundsException (I-§1.25)
If the nth value does not exist.

getComponents

public Component[] getComponents()
Returns:
an array of all the component in this container.

getLayout

public LayoutManager getLayout()
Returns:
the layout manager for this container.
See Also:
layout (II-§1.11.11)
setLayout (II-§1.11.22).

insets

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 (II-§3.7.1) 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.

Returns:
the insets of this container
See Also:
LayoutManager (II-§1.43).

layout

public void layout()
Lays out this container.
The layout method of Container calls the layoutContainer method (II-§1.43.2) 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 (II-§1.11.23).

Overrides:
layout in class Component (II-§1.10.33).
See Also:
setLayout (II-§1.11.22).

list

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 (II-§1.10.36) and then calls list on each of its subcomponents with and indentation of .

Parameters:
out - a print stream
indent - the number of spaces to indent
Overrides:
list in class Component (II-§1.10.36).

locate

public Component locate(int x, int y)
Determines the component or subcomponent of this container that contains the coordinate. This method only looks one level deep. If the point 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 coordinate is inside (II-§1.10.25) its own boundaries. If not, it returns null immediately. If the coordinate is inside its boundaries, it calls inside (II-§1.10.25) on each of the subcomponents; if any of those calls to returns true, that subcomponent is returned; otherwise the container target object is returned.

Parameters:
x - the x coordinate
y - the y coordinate
Returns:
this container or one of its subcomponent that contains the coordinate; null if the coordinate is outside this container.
Overrides:
locate in class Component (II-§1.10.37).

minimumSize

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 (II-§1.11.9). If so, its minimumLayoutSize method (II-§1.43.3) is called. Otherwise, its superclass's minimumSize method (II-§1.10.40) is called.

Returns:
the minimum size of this container.
Overrides:
minimumSize in class Component (II-§1.10.40).
See Also:
preferredSize (II-§1.11.17).

paintComponents

public void paintComponents(Graphics g)
Paints each of the components in th is container.
Parameters:
g - the graphics context
See Also:
paint in class Component (II-§1.10.49)
paintAll in class Component (II-§1.10.50).

paramString

protected String paramString()
Returns the parameter string representing the state of this container. This string is useful for debugging.
Returns:
the parameter string of this container.
Overrides:
paramString in class Component (II-§1.10.51).

preferredSize

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 (II-§1.11.9). If so, its preferredLayoutSize method (II-§1.43.4) is called. Otherwise, its superclass's preferredSize method (II-§1.10.53) is called.

Returns:
the minimum size of this container.
Overrides:
preferredSize in class Component (II-§1.10.53).
See Also:
minimumSize (II-§1.11.14).

printComponents

public void printComponents(Graphics g)
Prints each of the components in this container.
Parameters:
g - the graphics context
See Also:
print in class Component (II-§1.10.56)
printAll in class Component (II-§1.10.57).

remove

public void remove(Component comp)
Removes the specified component from this container. This method also causes the component to call its removeNotify method (II-§1.10.58) to remove its peer.

Parameters:
comp - the component to be removed
See Also:
add (II-§1.11.1).

removeAll

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 (II-§1.10.58) to remove their peers.

See Also:
add (II-§1.11.1)
remove (II-§1.11.19).

removeNotify

public void removeNotify()
Notifies this container and all its subcomponents to destroy their peers.
Overrides:
removeNotify in class Component (II-§1.10.58).
See Also:
addNotify (II-§1.11.4).

setLayout

public void setLayout(LayoutManager mgr)
Sets the layout manager for this container.
Parameters:
mgr - the new layout manager
See Also:
layout (II-§1.11.11)
getLayout (II-§1.11.9).

validate

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 (II-§1.10.75).
See Also:
invalidate in class Component (II-§1.10.26).


Packages  This Package  Prev  Next  Index
Java API Document (HTML generated by dkramer on April 22, 1996)
Copyright © 1996 Sun Microsystems, Inc. All rights reserved
Please send any comments or corrections to doug.kramer@sun.com