java.awt
Class Container
java.lang.Object
|
+--java.awt.Component
|
+--java.awt.Container
A generic window toolkit object that acts as a container for other objects.
Components are tracked in a list, and new elements are at the end of the
list or bottom of the stacking order.
Since:Authors:- original author unknown
- Eric Blake <ebb9@email.byu.edu>
java.awt.Component | add(java.awt.Component comp)
|
java.awt.Component | add(java.lang.String name, java.awt.Component comp)
|
java.awt.Component | add(java.awt.Component comp, int index)
|
void | add(java.awt.Component comp, java.lang.Object constraints)
|
void | add(java.awt.Component comp, java.lang.Object constraints, int index)
|
synchronized void | addContainerListener(java.awt.event.ContainerListener l)
|
void | addImpl(java.awt.Component comp, java.lang.Object constraints, int index)
|
void | addNotify()
|
void | addPropertyChangeListener(java.beans.PropertyChangeListener l)
|
void | addPropertyChangeListener(java.lang.String name, java.beans.PropertyChangeListener l)
|
void | applyComponentOrientation(java.awt.ComponentOrientation orientation)
|
boolean | areFocusTraversalKeysSet(int id)
|
int | countComponents()
|
void | deliverEvent(java.awt.Event e)
|
void | doLayout()
|
java.awt.Component | findComponentAt(int x, int y)
|
java.awt.Component | findComponentAt(java.awt.Point p)
|
float | getAlignmentX()
|
float | getAlignmentY()
|
java.awt.Component | getComponent(int n)
|
java.awt.Component | getComponentAt(int x, int y)
|
java.awt.Component | getComponentAt(java.awt.Point p)
|
int | getComponentCount()
|
java.awt.Component[] | getComponents()
|
synchronized java.awt.event.ContainerListener[] | getContainerListeners()
|
java.util.Set | getFocusTraversalKeys(int id)
|
java.awt.FocusTraversalPolicy | getFocusTraversalPolicy()
|
java.awt.Insets | getInsets()
|
java.awt.LayoutManager | getLayout()
|
java.util.EventListener[] | getListeners(java.lang.Class listenerType)
|
java.awt.Dimension | getMaximumSize()
|
java.awt.Dimension | getMinimumSize()
|
java.awt.Dimension | getPreferredSize()
|
java.awt.Insets | insets()
|
void | invalidate()
|
boolean | isAncestorOf(java.awt.Component comp)
|
boolean | isFocusCycleRoot(java.awt.Container c)
|
boolean | isFocusCycleRoot()
|
boolean | isFocusTraversalPolicySet()
|
void | layout()
|
void | list(java.io.PrintStream out, int indent)
|
void | list(java.io.PrintWriter out, int indent)
|
java.awt.Component | locate(int x, int y)
|
java.awt.Dimension | minimumSize()
|
void | paint(java.awt.Graphics g)
|
void | paintComponents(java.awt.Graphics g)
|
java.lang.String | paramString()
|
java.awt.Dimension | preferredSize()
|
void | print(java.awt.Graphics g)
|
void | printComponents(java.awt.Graphics g)
|
void | processContainerEvent(java.awt.event.ContainerEvent e)
|
void | processEvent(java.awt.AWTEvent e)
|
void | remove(int index)
|
void | remove(java.awt.Component comp)
|
void | removeAll()
|
synchronized void | removeContainerListener(java.awt.event.ContainerListener l)
|
void | removeNotify()
|
void | setFocusCycleRoot(boolean focusCycleRoot)
|
void | setFocusTraversalKeys(int id, java.util.Set keystrokes)
|
void | setFocusTraversalPolicy(java.awt.FocusTraversalPolicy policy)
|
void | setFont(java.awt.Font f)
|
void | setLayout(java.awt.LayoutManager mgr)
|
void | transferFocusBackward()
|
void | transferFocusDownCycle()
|
void | update(java.awt.Graphics g)
|
void | validate()
|
void | validateTree()
|
Container
public Container()
Default constructor for subclasses.
add
public Component add(java.awt.Component comp)
Adds the specified component to this container at the end of the
component list.
Parameters:
Returns:
- The same component that was added.
add
public Component add(java.awt.Component comp, int index)
Adds the specified component to this container at the specified index
in the component list.
Parameters:
Returns:
- The same component that was added.
Throws:
- If the specified index is invalid.
add
public void add(java.awt.Component comp, java.lang.Object constraints)
Adds the specified component to this container at the end of the
component list. The layout manager will use the specified constraints
when laying out this component.
Parameters:
add
public void add(java.awt.Component comp, java.lang.Object constraints, int index)
Adds the specified component to this container at the specified index
in the component list. The layout manager will use the specified
constraints when layout out this component.
Parameters:
Throws:
- If the specified index is invalid.
add
public Component add(java.lang.String name, java.awt.Component comp)
Adds the specified component to the container at the end of the
component list. This method should not be used. Instead, use
add(Component, Object
.
Parameters:
Returns:
- The same component that was added.
addContainerListener
public synchronized void addContainerListener(java.awt.event.ContainerListener l)
Adds the specified container listener to this object's list of
container listeners.
Parameters:
addImpl
protected void addImpl(java.awt.Component comp, java.lang.Object constraints, int index)
This method is called by all the 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:
Throws:
- If the specified index is invalid.
addNotify
public void addNotify()
Called when this container is added to another container to inform it
to create its peer. Peers for any child components will also be
created.
addPropertyChangeListener
public void addPropertyChangeListener(java.beans.PropertyChangeListener l)
Parameters:
addPropertyChangeListener
public void addPropertyChangeListener(java.lang.String name, java.beans.PropertyChangeListener l)
Parameters:
applyComponentOrientation
public void applyComponentOrientation(java.awt.ComponentOrientation orientation)
Sets the ComponentOrientation property of this container and all components
contained within it.
Since:Parameters:
Throws:
areFocusTraversalKeysSet
public 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.
If this method returns false, this Container is inheriting the Set from
an ancestor, or from the current KeyboardFocusManager.
Since:Parameters:
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.
countComponents
public int countComponents()
Returns the number of components in this container.
Returns:
- The number of components in this container.
deliverEvent
public void deliverEvent(java.awt.Event e)
AWT 1.0 event processor.
Parameters:
doLayout
public void doLayout()
Layout the components in this container.
findComponentAt
public Component findComponentAt(int x, int y)
Parameters:
findComponentAt
public Component findComponentAt(java.awt.Point p)
Parameters:
getAlignmentX
public float getAlignmentX()
Returns the preferred alignment along the X axis. This is a value
between 0 and 1 where 0 represents alignment flush left and
1 means alignment flush right, and 0.5 means centered.
Returns:
- The preferred alignment along the X axis.
getAlignmentY
public float getAlignmentY()
Returns the preferred alignment along the Y axis. This is a value
between 0 and 1 where 0 represents alignment flush top and
1 means alignment flush bottom, and 0.5 means centered.
Returns:
- The preferred alignment along the Y axis.
getComponent
public Component getComponent(int n)
Returns the component at the specified index.
Parameters:
Returns:
Throws:
getComponentAt
public Component getComponentAt(int x, int y)
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
case null
is returned.
Parameters:
Returns:
- The component containing the specified point, or
null
if there is no such point.
getComponentAt
public Component getComponentAt(java.awt.Point p)
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
case null
is returned.
Parameters:
Returns:
- The component containing the specified point, or
null
if there is no such point.
getComponentCount
public int getComponentCount()
Returns the number of components in this container.
Returns:
- The number of components in this container.
getComponents
public Component[] getComponents()
Returns an array of the components in this container.
Returns:
- The components in this container.
getContainerListeners
public synchronized ContainerListener[] getContainerListeners()
Since:
getFocusTraversalKeys
public Set getFocusTraversalKeys(int id)
Returns the Set of focus traversal keys for a given traversal operation for
this Container.
Since:Parameters:
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.
getFocusTraversalPolicy
public FocusTraversalPolicy getFocusTraversalPolicy()
getInsets
public Insets getInsets()
Returns the insets for this container, which is the space used for
borders, the margin, etc.
Returns:
- The insets for this container.
getLayout
public LayoutManager getLayout()
Returns the current layout manager for this container.
Returns:
- The layout manager for this container.
getListeners
public EventListener[] getListeners(java.lang.Class listenerType)
Returns an array of all the objects currently registered as FooListeners
upon this Container. FooListeners are registered using the addFooListener
method.
Since:Parameters:
Throws:
ClassCastException
- If listenerType doesn't specify a class or
interface that implements @see java.util.EventListener.
getMaximumSize
public Dimension getMaximumSize()
Returns the maximum size of this container.
Returns:
- The maximum size of this container.
getMinimumSize
public Dimension getMinimumSize()
Returns the minimum size of this container.
Returns:
- The minimum size of this container.
getPreferredSize
public Dimension getPreferredSize()
Returns the preferred size of this container.
Returns:
- The preferred size of this container.
insets
public Insets insets()
Returns the insets for this container, which is the space used for
borders, the margin, etc.
Returns:
- The insets for this container.
invalidate
public void invalidate()
Invalidates this container to indicate that it (and all parent
containers) need to be laid out.
isAncestorOf
public boolean isAncestorOf(java.awt.Component comp)
Tests whether or not the specified component is contained within
this components subtree.
Parameters:
Returns:
true
if this container is an ancestor of the
specified component, false
otherwise.
isFocusCycleRoot
public boolean isFocusCycleRoot()
isFocusCycleRoot
public boolean isFocusCycleRoot(java.awt.Container c)
Parameters:
isFocusTraversalPolicySet
public boolean isFocusTraversalPolicySet()
layout
public void layout()
Layout the components in this container.
list
public void list(java.io.PrintStream out, int indent)
Writes a listing of this container to the specified stream starting
at the specified indentation point.
Parameters:
list
public void list(java.io.PrintWriter out, int indent)
Writes a listing of this container to the specified stream starting
at the specified indentation point.
Parameters:
locate
public Component locate(int x, int y)
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
case null
is returned.
Parameters:
Returns:
- The component containing the specified point, or
null
if there is no such point.
minimumSize
public Dimension minimumSize()
Returns the minimum size of this container.
Returns:
- The minimum size of this container.
paint
public void paint(java.awt.Graphics g)
Paints this container. The implementation of this method in this
class forwards to any lightweight components in this container. If
this method is subclassed, this method should still be invoked as
a superclass method so that lightweight components are properly
drawn.
Parameters:
paintComponents
public void paintComponents(java.awt.Graphics g)
Paints all of the components in this container.
Parameters:
paramString
protected String paramString()
Returns a string representing the state of this container for
debugging purposes.
Returns:
- A string representing the state of this container.
preferredSize
public Dimension preferredSize()
Returns the preferred size of this container.
Returns:
- The preferred size of this container.
print
public void print(java.awt.Graphics g)
Prints this container. The implementation of this method in this
class forwards to any lightweight components in this container. If
this method is subclassed, this method should still be invoked as
a superclass method so that lightweight components are properly
drawn.
Parameters:
printComponents
public void printComponents(java.awt.Graphics g)
Prints all of the components in this container.
Parameters:
processContainerEvent
protected void processContainerEvent(java.awt.event.ContainerEvent e)
Called when a container event occurs if container events are enabled.
This method calls any registered listeners.
Parameters:
processEvent
protected void processEvent(java.awt.AWTEvent e)
Processes the specified event. This method calls
processContainerEvent()
if this method is a
ContainerEvent
, otherwise it calls the superclass
method.
Parameters:
remove
public void remove(int index)
Removes the component at the specified index from this container.
Parameters:
remove
public void remove(java.awt.Component comp)
Removes the specified component from this container.
Parameters:
Returns:
- component The component to remove from this container.
removeAll
public void removeAll()
Removes all components from this container.
removeContainerListener
public synchronized void removeContainerListener(java.awt.event.ContainerListener l)
Removes the specified container listener from this object's list of
container listeners.
Parameters:
removeNotify
public void removeNotify()
Called when this container is removed from its parent container to
inform it to destroy its peer. This causes the peers of all child
component to be destroyed as well.
setFocusCycleRoot
public void setFocusCycleRoot(boolean focusCycleRoot)
Parameters:
setFocusTraversalKeys
public void setFocusTraversalKeys(int id, java.util.Set keystrokes)
Sets the focus traversal keys for a given traversal operation for this
Container.
Since:Parameters:
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.
setFocusTraversalPolicy
public void setFocusTraversalPolicy(java.awt.FocusTraversalPolicy policy)
Parameters:
setFont
public void setFont(java.awt.Font f)
Parameters:
setLayout
public void setLayout(java.awt.LayoutManager mgr)
Sets the layout manager for this container to the specified layout
manager.
Parameters:
transferFocusBackward
public void transferFocusBackward()
transferFocusDownCycle
public void transferFocusDownCycle()
update
public void update(java.awt.Graphics g)
Updates this container. The implementation of this method in this
class forwards to any lightweight components in this container. If
this method is subclassed, this method should still be invoked as
a superclass method so that lightweight components are properly
drawn.
Parameters:
validate
public void validate()
Re-lays out the components in this container.
validateTree
protected void validateTree()
Recursively validates the container tree, recomputing any invalid
layouts.