java.awt
public class Container extends Component
Since: 1.0
UNKNOWN: still missing 1.4 support, some generics from 1.5
Nested Class Summary | |
---|---|
protected class | Container.AccessibleAWTContainer
This class provides accessibility support for subclasses of container.
|
Constructor Summary | |
---|---|
Container()
Default constructor for subclasses. |
Method Summary | |
---|---|
Component | add(Component comp)
Adds the specified component to this container at the end of the
component list.
|
Component | add(String name, Component comp)
Adds the specified component to the container at the end of the
component list. |
Component | add(Component comp, int index)
Adds the specified component to this container at the specified index
in the component list.
|
void | add(Component comp, Object constraints)
Adds the specified component to this container at the end of the
component list. |
void | add(Component comp, Object constraints, int index)
Adds the specified component to this container at the specified index
in the component list. |
void | addContainerListener(ContainerListener listener)
Adds the specified container listener to this object's list of
container listeners.
|
protected void | addImpl(Component comp, Object constraints, int index)
This method is called by all the add() methods to perform
the actual adding of the component. |
void | addNotify()
Called when this container is added to another container to inform it
to create its peer. |
void | addPropertyChangeListener(PropertyChangeListener listener) |
void | addPropertyChangeListener(String propertyName, PropertyChangeListener listener) |
void | applyComponentOrientation(ComponentOrientation orientation)
Sets the ComponentOrientation property of this container and all components
contained within it.
|
boolean | areFocusTraversalKeysSet(int id)
Returns whether the Set of focus traversal keys for the given focus
traversal operation has been explicitly defined for this Container.
|
int | countComponents()
Returns the number of components in this container.
|
void | deliverEvent(Event e)
AWT 1.0 event processor.
|
void | doLayout()
Layout the components in this container. |
Component | findComponentAt(int x, int y)
Locates the visible child component that contains the specified position.
|
Component | findComponentAt(Point p)
Locates the visible child component that contains the specified position.
|
float | getAlignmentX()
Returns the preferred alignment along the X axis. |
float | getAlignmentY()
Returns the preferred alignment along the Y axis. |
Component | getComponent(int n)
Returns the component at the specified index.
|
Component | getComponentAt(int x, int y)
Returns the component located at the specified point. |
Component | getComponentAt(Point p)
Returns the component located at the specified point. |
int | getComponentCount()
Returns the number of components in this container.
|
Component[] | getComponents()
Returns an array of the components in this container.
|
int | getComponentZOrder(Component comp)
Returns the Z ordering index of comp . |
ContainerListener[] | getContainerListeners() |
Set<AWTKeyStroke> | getFocusTraversalKeys(int id)
Returns the Set of focus traversal keys for a given traversal operation for
this Container.
|
FocusTraversalPolicy | getFocusTraversalPolicy()
Return the focus traversal policy that determines the focus
traversal order for this Container's children. |
Insets | getInsets()
Returns the insets for this container, which is the space used for
borders, the margin, etc.
|
LayoutManager | getLayout()
Returns the current layout manager for this container.
|
<T extends EventListener> T[] | getListeners(Class<T> listenerType)
Returns all registered {@link EventListener}s of the given
listenerType .
|
Dimension | getMaximumSize()
Returns the maximum size of this container.
|
Dimension | getMinimumSize()
Returns the minimum size of this container.
|
Dimension | getPreferredSize()
Returns the preferred size of this container.
|
Insets | insets()
Returns the insets for this container, which is the space used for
borders, the margin, etc.
|
void | invalidate()
Invalidates this container to indicate that it (and all parent
containers) need to be laid out. |
boolean | isAncestorOf(Component comp)
Tests whether or not the specified component is contained within
this components subtree.
|
boolean | isFocusCycleRoot(Container c)
Check whether the given Container is the focus cycle root of this
Container's focus traversal cycle. |
boolean | isFocusCycleRoot()
Check whether this Container is a focus cycle root.
|
boolean | isFocusTraversalPolicyProvider()
Set to true if this container provides a focus traversal
policy, false when the root container's focus
traversal policy should be used.
|
boolean | isFocusTraversalPolicySet()
Check whether this Container's focus traversal policy has been
explicitly set. |
void | layout()
Layout the components in this container.
|
void | list(PrintStream out, int indent)
Writes a listing of this container to the specified stream starting
at the specified indentation point.
|
void | list(PrintWriter out, int indent)
Writes a listing of this container to the specified stream starting
at the specified indentation point.
|
Component | locate(int x, int y)
Returns the component located at the specified point. |
Dimension | minimumSize()
Returns the minimum size of this container.
|
void | paint(Graphics g)
Paints this container. |
void | paintComponents(Graphics g)
Paints all of the components in this container.
|
protected String | paramString()
Returns a string representing the state of this container for
debugging purposes.
|
Dimension | preferredSize()
Returns the preferred size of this container.
|
void | print(Graphics g)
Prints this container. |
void | printComponents(Graphics g)
Prints all of the components in this container.
|
protected void | processContainerEvent(ContainerEvent e)
Called when a container event occurs if container events are enabled.
|
protected void | processEvent(AWTEvent e)
Processes the specified event. |
void | remove(int index)
Removes the component at the specified index from this container.
|
void | remove(Component comp)
Removes the specified component from this container.
|
void | removeAll()
Removes all components from this container. |
void | removeContainerListener(ContainerListener listener)
Removes the specified container listener from this object's list of
container listeners.
|
void | removeNotify()
Called when this container is removed from its parent container to
inform it to destroy its peer. |
void | setComponentZOrder(Component comp, int index)
Sets the Z ordering for the component comp to
index . |
void | setFocusCycleRoot(boolean focusCycleRoot)
Set whether or not this Container is the root of a focus
traversal cycle. |
void | setFocusTraversalKeys(int id, Set<? extends AWTKeyStroke> keystrokes)
Sets the focus traversal keys for a given traversal operation for this
Container.
|
void | setFocusTraversalPolicy(FocusTraversalPolicy policy)
If this Container is a focus cycle root, set the focus traversal
policy that determines the focus traversal order for its
children. |
void | setFocusTraversalPolicyProvider(boolean b)
Set to true if this container provides a focus traversal
policy, false when the root container's focus
traversal policy should be used.
|
void | setFont(Font f) |
void | setLayout(LayoutManager mgr)
Sets the layout manager for this container to the specified layout
manager.
|
void | transferFocusDownCycle()
Transfer focus down one focus traversal cycle. |
void | update(Graphics g)
Updates this container. |
void | validate()
Re-lays out the components in this container. |
protected void | validateTree()
Recursively validates the container tree, recomputing any invalid
layouts. |
Parameters: comp The component to add to the container.
Returns: The same component that was added.
add(Component, Object)
.
Parameters: name The name of the component to be added. comp The component to be added.
Returns: The same component that was added.
See Also: add
Parameters: comp The component to be added. index The index in the component list to insert this child at, or -1 to add at the end of the list.
Returns: The same component that was added.
Throws: ArrayIndexOutOfBoundsException If the specified index is invalid.
Parameters: comp The component to be added to this container. constraints The layout constraints for this component.
Parameters: comp The component to be added. constraints The layout constraints for this component. index The index in the component list to insert this child at, or -1 to add at the end of the list.
Throws: ArrayIndexOutOfBoundsException If the specified index is invalid.
Parameters: listener The listener to add.
add()
methods to perform
the actual adding of the component. Subclasses who wish to perform
their own processing when a component is added should override this
method. Any subclass doing this must call the superclass version of
this method in order to ensure proper functioning of the container.
Parameters: comp The component to be added. constraints The layout constraints for this component, or
null
if there are no constraints. index The index in the component list to insert this child
at, or -1 to add at the end of the list.
Throws: ArrayIndexOutOfBoundsException If the specified index is invalid.
Throws: NullPointerException If orientation is null
Since: 1.4
Throws: IllegalArgumentException If id is not one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS.
Since: 1.4
Deprecated: use {@link #getComponentCount()} instead
Returns the number of components in this container.Returns: The number of components in this container.
Deprecated: use {@link #dispatchEvent(AWTEvent)} instead
AWT 1.0 event processor.Parameters: e The event that occurred.
Parameters: x - x coordinate y - y coordinate
Returns: null if the component does not contain the position. If there is no child component at the requested point and the point is within the bounds of the container the container itself is returned.
Parameters: p - the component's location
Returns: null if the component does not contain the position. If there is no child component at the requested point and the point is within the bounds of the container the container itself is returned.
Returns: The preferred alignment along the X axis.
Returns: The preferred alignment along the Y axis.
Parameters: n The index of the component to retrieve.
Returns: The requested component.
Throws: ArrayIndexOutOfBoundsException If the specified index is invalid
null
is returned.
When components overlap, the first component is returned. The component
that is closest to (x, y), containing that location, is returned.
Heavyweight components take precedence of lightweight components.
This function does not ignore invisible components. If there is an invisible
component at (x,y), it will be returned.
Parameters: x The X coordinate of the point. y The Y coordinate of the point.
Returns: The component containing the specified point, or
null
if there is no such point.
null
is returned.
The top-most child component is returned in the case where components overlap.
This is determined by finding the component closest to (x,y) and contains
that location. Heavyweight components take precedence of lightweight components.
This function does not ignore invisible components. If there is an invisible
component at (x,y), it will be returned.
Parameters: p The point to return the component at.
Returns: The component containing the specified point, or null
if there is no such point.
Returns: The number of components in this container.
Returns: The components in this container.
comp
. If comp
is not a child component of this Container, this returns -1
.
Parameters: comp the component for which to query the Z ordering
Returns: the Z ordering index of comp
or -1
if
comp
is not a child of this Container
Since: 1.5
Since: 1.4
Throws: IllegalArgumentException If id is not one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS.
Since: 1.4
Returns: this Container's focus traversal policy or null
Since: 1.4
Returns: The insets for this container.
Returns: The layout manager for this container.
listenerType
.
Parameters: listenerType the class of listeners to filter (null
not permitted).
Returns: An array of registered listeners.
Throws: ClassCastException if listenerType
does not implement
the {@link EventListener} interface. NullPointerException if listenerType
is
null
.
Since: 1.3
Returns: The maximum size of this container.
Returns: The minimum size of this container.
Returns: The preferred size of this container.
Deprecated: use {@link #getInsets()} instead
Returns the insets for this container, which is the space used for borders, the margin, etc.Returns: The insets for this container.
Parameters: comp The component to test.
Returns: true
if this container is an ancestor of the
specified component, false
otherwise.
c
is either of those containers, this
method will return true.
Parameters: c the candidate Container
Returns: true if c is the focus cycle root of the focus traversal cycle to which this Container belongs, false otherwise
Since: 1.4
Returns: true if this is a focus cycle root, false otherwise
Since: 1.4
true
if this container provides a focus traversal
policy, false
when the root container's focus
traversal policy should be used.
Returns: true
if this container provides a focus traversal
policy, false
when the root container's focus
traversal policy should be used
Since: 1.5
Returns: true if focus traversal policy is set, false otherwise
Deprecated: use {@link #doLayout()} instead
Layout the components in this container.Parameters: out The PrintStream
to write to. indent The indentation point.
Parameters: out The PrintWriter
to write to. indent The indentation point.
Deprecated: use {@link #getComponentAt(int, int)} instead
Returns the component located at the specified point. This is done by checking whether or not a child component claims to contain this point. The first child component that does is returned. If no child component claims the point, the container itself is returned, unless the point does not exist within this container, in which casenull
is returned.
When components overlap, the first component is returned. The component
that is closest to (x, y), containing that location, is returned.
Heavyweight components take precedence of lightweight components.
This function does not ignore invisible components. If there is an invisible
component at (x,y), it will be returned.
Parameters: x The x position of the point to return the component at. y The y position of the point to return the component at.
Returns: The component containing the specified point, or null
if there is no such point.
Deprecated: use {@link #getMinimumSize()} instead
Returns the minimum size of this container.Returns: The minimum size of this container.
Parameters: g - The graphics context for this paint job.
Parameters: g The graphics context for this paint job.
Returns: A string representing the state of this container.
Deprecated: use {@link #getPreferredSize()} instead
Returns the preferred size of this container.Returns: The preferred size of this container.
Parameters: g The graphics context for this print job.
Parameters: g The graphics context for this print job.
Parameters: e The event that occurred.
processContainerEvent()
if this method is a
ContainerEvent
, otherwise it calls the superclass
method.
Parameters: e The event to be processed.
Parameters: index The index of the component to remove.
Parameters: comp The component to remove from this container.
Parameters: listener The listener to remove.
comp
to
index
. Components with lower Z order paint above components
with higher Z order.
Parameters: comp the component for which to change the Z ordering index the index to set
Throws: NullPointerException if comp == null
IllegalArgumentException if comp is an ancestor of this container IllegalArgumentException if index
is not in
[0, getComponentCount()]
for moving between
containers or [0, getComponentCount() - 1]
for moving
inside this container IllegalArgumentException if comp == this
IllegalArgumentException if comp
is a
Window
Since: 1.5
Parameters: focusCycleRoot true if this is a focus cycle root, false otherwise
Since: 1.4
Throws: IllegalArgumentException If id is not one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS, or if keystrokes contains null, or if any Object in keystrokes is not an AWTKeyStroke, or if any keystroke represents a KEY_TYPED event, or if any keystroke already maps to another focus traversal operation for this Container.
Since: 1.4
policy
is null, this
Container will inherit its policy from the closest ancestor focus
cycle root that's had its policy set.
Parameters: policy the new focus traversal policy for this Container or null
Since: 1.4
true
if this container provides a focus traversal
policy, false
when the root container's focus
traversal policy should be used.
Parameters: b true
if this container provides a focus traversal
policy, false
when the root container's focus
traversal policy should be used
Since: 1.5
Parameters: mgr The new layout manager for this container.
Since: 1.4
Parameters: g The graphics context for this update.
UNKNOWN: The specification suggests that this method forwards the update() call to all its lightweight children. Tests show that this is not done either in the JDK. The exact behaviour seems to be that the background is cleared in heavyweight Containers, and all other containers directly call paint(), causing the (lightweight) children to be painted.