|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
java.awt.Container
public class 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.
Nested Class Summary | |
---|---|
protected class |
Container.AccessibleAWTContainer
This class provides accessibility support for subclasses of container. |
Nested classes/interfaces inherited from class java.awt.Component |
---|
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy |
Field Summary |
---|
Fields inherited from class java.awt.Component |
---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
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(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. |
|
Component |
add(String name,
Component comp)
Adds the specified component to the container at the end of 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)
Adds the specified property listener to this component. |
|
void |
addPropertyChangeListener(String propertyName,
PropertyChangeListener listener)
Adds the specified property listener to this component. |
|
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()
Deprecated. use getComponentCount() instead |
|
void |
deliverEvent(Event e)
Deprecated. use Component.dispatchEvent(AWTEvent) instead |
|
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. |
|
|
getListeners(Class<T> listenerType)
Returns all registered EventListener s of the given
listenerType . |
|
Dimension |
getMaximumSize()
Returns the maximum size of this container. |
|
Dimension |
getMinimumSize()
Returns the minimum size of this container. |
|
Point |
getMousePosition(boolean allowChildren)
Returns the mouse pointer position relative to this Container's top-left corner. |
|
Dimension |
getPreferredSize()
Returns the preferred size of this container. |
|
Insets |
insets()
Deprecated. use getInsets() instead |
|
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()
Check whether this Container is a focus cycle root. |
|
boolean |
isFocusCycleRoot(Container c)
Check whether the given Container is the focus cycle root of this Container's focus traversal cycle. |
|
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()
Deprecated. use doLayout() instead |
|
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)
Deprecated. use getComponentAt(int, int) instead |
|
Dimension |
minimumSize()
Deprecated. use getMinimumSize() instead |
|
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()
Deprecated. use getPreferredSize() instead |
|
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(Component comp)
Removes the specified component from this container. |
|
void |
remove(int index)
Removes the component at the specified index 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)
Sets the font for this component to the specified font. |
|
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Container()
Method Detail |
---|
public int getComponentCount()
public int countComponents()
getComponentCount()
instead
public Component getComponent(int n)
n
- The index of the component to retrieve.
ArrayIndexOutOfBoundsException
- If the specified index is invalidpublic Component[] getComponents()
public Insets getInsets()
public Insets insets()
getInsets()
instead
public Component add(Component comp)
comp
- The component to add to the container.
public Component add(String name, Component comp)
add(Component, Object)
.
name
- The name of the component to be added.comp
- The component to be added.
add(Component,Object)
public Component add(Component comp, int index)
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.
ArrayIndexOutOfBoundsException
- If the specified index is invalid.public void add(Component comp, Object constraints)
comp
- The component to be added to this container.constraints
- The layout constraints for this component.public void add(Component comp, Object constraints, int index)
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.
ArrayIndexOutOfBoundsException
- If the specified index is invalid.protected void addImpl(Component comp, Object constraints, int index)
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.
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.
ArrayIndexOutOfBoundsException
- If the specified index is invalid.public void remove(int index)
index
- The index of the component to remove.public void remove(Component comp)
comp
- The component to remove from this container.public void removeAll()
public LayoutManager getLayout()
public void setLayout(LayoutManager mgr)
mgr
- The new layout manager for this container.public void doLayout()
doLayout
in class Component
Component.validate()
,
LayoutManager
public void layout()
doLayout()
instead
layout
in class Component
public void invalidate()
invalidate
in class Component
public void validate()
validate
in class Component
Component.invalidate()
,
Component.doLayout()
,
LayoutManager
,
validate()
protected void validateTree()
public void setFont(Font f)
Component
setFont
in class Component
f
- the new font for this componentComponent.getFont()
public Dimension getPreferredSize()
getPreferredSize
in class Component
Component.getMinimumSize()
,
Component.setPreferredSize(Dimension)
,
LayoutManager
public Dimension preferredSize()
getPreferredSize()
instead
preferredSize
in class Component
public Dimension getMinimumSize()
getMinimumSize
in class Component
Component.getPreferredSize()
,
Component.setMinimumSize(Dimension)
,
LayoutManager
public Dimension minimumSize()
getMinimumSize()
instead
minimumSize
in class Component
public Dimension getMaximumSize()
getMaximumSize
in class Component
Component.getMinimumSize()
,
Component.setMaximumSize(Dimension)
,
Component.getPreferredSize()
,
LayoutManager
public float getAlignmentX()
getAlignmentX
in class Component
public float getAlignmentY()
getAlignmentY
in class Component
public void paint(Graphics g)
paint
in class Component
g
- - The graphics context for this paint job.Component.update(Graphics)
public void update(Graphics g)
update
in class Component
g
- The graphics context for this update.Component.paint(Graphics)
,
Component.repaint()
public void print(Graphics g)
print
in class Component
g
- The graphics context for this print job.Component.paint(Graphics)
public void paintComponents(Graphics g)
g
- The graphics context for this paint job.public void printComponents(Graphics g)
g
- The graphics context for this print job.public void addContainerListener(ContainerListener listener)
listener
- The listener to add.public void removeContainerListener(ContainerListener listener)
listener
- The listener to remove.public ContainerListener[] getContainerListeners()
public <T extends EventListener> T[] getListeners(Class<T> listenerType)
EventListener
s of the given
listenerType
.
getListeners
in class Component
listenerType
- the class of listeners to filter (null
not permitted).
ClassCastException
- if listenerType
does not implement
the EventListener
interface.
NullPointerException
- if listenerType
is
null
.getContainerListeners()
protected void processEvent(AWTEvent e)
processContainerEvent()
if this method is a
ContainerEvent
, otherwise it calls the superclass
method.
processEvent
in class Component
e
- The event to be processed.Component.processComponentEvent(ComponentEvent)
,
Component.processFocusEvent(FocusEvent)
,
Component.processKeyEvent(KeyEvent)
,
Component.processMouseEvent(MouseEvent)
,
Component.processMouseMotionEvent(MouseEvent)
,
Component.processInputMethodEvent(InputMethodEvent)
,
Component.processHierarchyEvent(HierarchyEvent)
,
Component.processMouseWheelEvent(MouseWheelEvent)
protected void processContainerEvent(ContainerEvent e)
e
- The event that occurred.public void deliverEvent(Event e)
Component.dispatchEvent(AWTEvent)
instead
deliverEvent
in class Component
e
- The event that occurred.public Component getComponentAt(int x, int y)
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.
getComponentAt
in class Component
x
- The X coordinate of the point.y
- The Y coordinate of the point.
null
if there is no such point.Component.contains(int, int)
public Point getMousePosition(boolean allowChildren) throws HeadlessException
allowChildren
- true to allow descendents, false if pointer
must be directly over Container.
HeadlessException
- if in a headless environmentpublic Component locate(int x, int y)
getComponentAt(int, int)
instead
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.
locate
in class Component
x
- The x position of the point to return the component at.y
- The y position of the point to return the component at.
null
if there is no such point.public Component getComponentAt(Point p)
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.
getComponentAt
in class Component
p
- The point to return the component at.
null
if there is no such point.Component.contains(Point)
public Component findComponentAt(int x, int y)
x
- - x coordinatey
- - y coordinate
public Component findComponentAt(Point p)
p
- - the component's location
public void addNotify()
addNotify
in class Component
Component.isDisplayable()
,
Component.removeNotify()
public void removeNotify()
removeNotify
in class Component
Component.isDisplayable()
,
Component.addNotify()
public boolean isAncestorOf(Component comp)
comp
- The component to test.
true
if this container is an ancestor of the
specified component, false
otherwise.protected String paramString()
paramString
in class Component
public void list(PrintStream out, int indent)
list
in class Component
out
- The PrintStream
to write to.indent
- The indentation point.public void list(PrintWriter out, int indent)
list
in class Component
out
- The PrintWriter
to write to.indent
- The indentation point.public void setFocusTraversalKeys(int id, Set<? extends AWTKeyStroke> keystrokes)
setFocusTraversalKeys
in class Component
id
- one of FORWARD_TRAVERSAL_KEYS, BACKWARD_TRAVERSAL_KEYS, or
UP_CYCLE_TRAVERSAL_KEYSkeystrokes
- a set of keys, or null
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.Component.getFocusTraversalKeys(int)
,
KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS
,
KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS
,
KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS
public Set<AWTKeyStroke> getFocusTraversalKeys(int id)
getFocusTraversalKeys
in class Component
id
- one of FORWARD_TRAVERSAL_KEYS, BACKWARD_TRAVERSAL_KEYS,
or UP_CYCLE_TRAVERSAL_KEYS
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.(int, Set)
,
KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS
,
KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS
,
KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS
public boolean areFocusTraversalKeysSet(int id)
areFocusTraversalKeysSet
in class Component
id
- one of FORWARD_TRAVERSAL_KEYS, BACKWARD_TRAVERSAL_KEYS,
or UP_CYCLE_TRAVERSAL_KEYS
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.(int)
,
KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS
,
KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS
,
KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS
public boolean isFocusCycleRoot(Container c)
c
is either of those containers, this
method will return true.
isFocusCycleRoot
in class Component
c
- the candidate Container
public void setFocusTraversalPolicy(FocusTraversalPolicy policy)
policy
is null, this
Container will inherit its policy from the closest ancestor focus
cycle root that's had its policy set.
policy
- the new focus traversal policy for this Container or nullpublic FocusTraversalPolicy getFocusTraversalPolicy()
public boolean isFocusTraversalPolicySet()
public void setFocusCycleRoot(boolean focusCycleRoot)
focusCycleRoot
- true if this is a focus cycle root, false otherwisepublic final boolean isFocusTraversalPolicyProvider()
true
if this container provides a focus traversal
policy, false
when the root container's focus
traversal policy should be used.
true
if this container provides a focus traversal
policy, false
when the root container's focus
traversal policy should be usedsetFocusTraversalPolicyProvider(boolean)
public final void setFocusTraversalPolicyProvider(boolean b)
true
if this container provides a focus traversal
policy, false
when the root container's focus
traversal policy should be used.
b
- true
if this container provides a focus traversal
policy, false
when the root container's focus
traversal policy should be usedisFocusTraversalPolicyProvider()
public boolean isFocusCycleRoot()
public void transferFocusDownCycle()
public void applyComponentOrientation(ComponentOrientation orientation)
applyComponentOrientation
in class Component
orientation
- the new orientation
NullPointerException
- If orientation is nullComponent.getComponentOrientation()
public void addPropertyChangeListener(PropertyChangeListener listener)
Component
"font"
)"background"
)"foreground"
)"focusable"
)"focusTraversalKeysEnabled"
)"forwardFocusTraversalKeys"
)"backwardFocusTraversalKeys"
)"upCycleFocusTraversalKeys"
)
addPropertyChangeListener
in class Component
listener
- the new listener to addComponent.removePropertyChangeListener(PropertyChangeListener)
,
Component.getPropertyChangeListeners()
,
Component.addPropertyChangeListener(String, PropertyChangeListener)
public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
Component
"font"
)"background"
)"foreground"
)"focusable"
)"focusTraversalKeysEnabled"
)"forwardFocusTraversalKeys"
)"backwardFocusTraversalKeys"
)"upCycleFocusTraversalKeys"
)
addPropertyChangeListener
in class Component
propertyName
- the property name to filter onlistener
- the new listener to addComponent.removePropertyChangeListener(String, PropertyChangeListener)
,
Component.getPropertyChangeListeners(String)
,
Component.addPropertyChangeListener(PropertyChangeListener)
public final void setComponentZOrder(Component comp, int index)
comp
to
index
. Components with lower Z order paint above components
with higher Z order.
comp
- the component for which to change the Z orderingindex
- the index to set
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
getComponentZOrder(Component)
public final int getComponentZOrder(Component comp)
comp
. If comp
is not a child component of this Container, this returns -1
.
comp
- the component for which to query the Z ordering
comp
or -1
if
comp
is not a child of this ContainersetComponentZOrder(Component, int)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |