GeezerVison is showing docs.oracle.com — Container (Java Platform SE 8 )
Java™ Platform Standard Ed. 8
-
-
Nested Class Summary
Nested Classes
| Modifier and Type |
Class |
Description |
protected class |
Container.AccessibleAWTContainer |
Inner class of Container used to provide default support for
accessibility.
|
-
Constructor Summary
Constructors
| Constructor |
Description |
Container() |
Constructs a new Container.
|
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods
| Modifier and Type |
Method |
Description |
Component |
add(Component comp) |
Appends the specified component to the end of this container.
|
Component |
add(Component comp,
int index) |
Adds the specified component to this container at the given
position.
|
void |
add(Component comp,
Object constraints) |
Adds the specified component to the end of this container.
|
void |
add(Component comp,
Object constraints,
int index) |
Adds the specified component to this container with the specified
constraints at the specified index.
|
Component |
add(String name,
Component comp) |
Adds the specified component to this container.
|
void |
addContainerListener(ContainerListener l) |
Adds the specified container listener to receive container events
from this container.
|
protected void |
addImpl(Component comp,
Object constraints,
int index) |
Adds the specified component to this container at the specified
index.
|
void |
addNotify() |
Makes this Container displayable by connecting it to
a native screen resource.
|
void |
addPropertyChangeListener(PropertyChangeListener listener) |
Adds a PropertyChangeListener to the listener list.
|
void |
addPropertyChangeListener(String propertyName,
PropertyChangeListener listener) |
Adds a PropertyChangeListener to the listener list for a specific
property.
|
void |
applyComponentOrientation(ComponentOrientation o) |
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.
As of JDK version 1.1,
replaced by getComponentCount().
|
void |
deliverEvent(Event e) |
Deprecated.
As of JDK version 1.1,
replaced by dispatchEvent(AWTEvent e)
|
void |
doLayout() |
Causes this container to lay out its components.
|
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
point.
|
float |
getAlignmentX() |
Returns the alignment along the x axis.
|
float |
getAlignmentY() |
Returns the alignment along the y axis.
|
Component |
getComponent(int n) |
Gets the nth component in this container.
|
Component |
getComponentAt(int x,
int y) |
Locates the component that contains the x,y position.
|
Component |
getComponentAt(Point p) |
Gets the component that contains the specified point.
|
int |
getComponentCount() |
Gets the number of components in this panel.
|
Component[] |
getComponents() |
Gets all the components in this container.
|
int |
getComponentZOrder(Component comp) |
Returns the z-order index of the component inside the container.
|
ContainerListener[] |
getContainerListeners() |
Returns an array of all the container listeners
registered on this container.
|
Set<AWTKeyStroke> |
getFocusTraversalKeys(int id) |
Returns the Set of focus traversal keys for a given traversal operation
for this Container.
|
FocusTraversalPolicy |
getFocusTraversalPolicy() |
Returns the focus traversal policy that will manage keyboard traversal
of this Container's children, or null if this Container is not a focus
cycle root.
|
Insets |
getInsets() |
Determines the insets of this container, which indicate the size
of the container's border.
|
LayoutManager |
getLayout() |
Gets the layout manager for this container.
|
<T extends EventListener> T[] |
getListeners(Class<T> listenerType) |
Returns an array of all the objects currently registered
as FooListeners
upon this Container.
|
Dimension |
getMaximumSize() |
Returns the maximum size of this container.
|
Dimension |
getMinimumSize() |
Returns the minimum size of this container.
|
Point |
getMousePosition(boolean allowChildren) |
Returns the position of the mouse pointer in this Container's
coordinate space if the Container is under the mouse pointer,
otherwise returns null.
|
Dimension |
getPreferredSize() |
Returns the preferred size of this container.
|
Insets |
insets() |
Deprecated.
As of JDK version 1.1,
replaced by getInsets().
|
void |
invalidate() |
Invalidates the container.
|
boolean |
isAncestorOf(Component c) |
Checks if the component is contained in the component hierarchy of
this container.
|
boolean |
isFocusCycleRoot() |
Returns whether this Container is the root of a focus traversal cycle.
|
boolean |
isFocusCycleRoot(Container container) |
Returns whether the specified Container is the focus cycle root of this
Container's focus traversal cycle.
|
boolean |
isFocusTraversalPolicyProvider() |
Returns whether this container provides focus traversal
policy.
|
boolean |
isFocusTraversalPolicySet() |
Returns whether the focus traversal policy has been explicitly set for
this Container.
|
boolean |
isValidateRoot() |
Indicates if this container is a validate root.
|
void |
layout() |
Deprecated.
As of JDK version 1.1,
replaced by doLayout().
|
void |
list(PrintStream out,
int indent) |
Prints a listing of this container to the specified output
stream.
|
void |
list(PrintWriter out,
int indent) |
Prints out a list, starting at the specified indentation,
to the specified print writer.
|
Component |
locate(int x,
int y) |
Deprecated.
As of JDK version 1.1,
replaced by getComponentAt(int, int).
|
Dimension |
minimumSize() |
Deprecated.
As of JDK version 1.1,
replaced by getMinimumSize().
|
void |
paint(Graphics g) |
Paints the container.
|
void |
paintComponents(Graphics g) |
Paints each of the components in this container.
|
protected String |
paramString() |
Returns a string representing the state of this Container.
|
Dimension |
preferredSize() |
Deprecated.
As of JDK version 1.1,
replaced by getPreferredSize().
|
void |
print(Graphics g) |
Prints the container.
|
void |
printComponents(Graphics g) |
Prints each of the components in this container.
|
protected void |
processContainerEvent(ContainerEvent e) |
Processes container events occurring on this container by
dispatching them to any registered ContainerListener objects.
|
protected void |
processEvent(AWTEvent e) |
Processes events on this container.
|
void |
remove(Component comp) |
Removes the specified component from this container.
|
void |
remove(int index) |
Removes the component, specified by index,
from this container.
|
void |
removeAll() |
Removes all the components from this container.
|
void |
removeContainerListener(ContainerListener l) |
Removes the specified container listener so it no longer receives
container events from this container.
|
void |
removeNotify() |
Makes this Container undisplayable by removing its connection
to its native screen resource.
|
void |
setComponentZOrder(Component comp,
int index) |
Moves the specified component to the specified z-order index in
the container.
|
void |
setFocusCycleRoot(boolean focusCycleRoot) |
Sets whether 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) |
Sets the focus traversal policy that will manage keyboard traversal of
this Container's children, if this Container is a focus cycle root.
|
void |
setFocusTraversalPolicyProvider(boolean provider) |
Sets whether this container will be used to provide focus
traversal policy.
|
void |
setFont(Font f) |
Sets the font of this container.
|
void |
setLayout(LayoutManager mgr) |
Sets the layout manager for this container.
|
void |
transferFocusDownCycle() |
Transfers the focus down one focus traversal cycle.
|
void |
update(Graphics g) |
Updates the container.
|
void |
validate() |
Validates this container and all of its subcomponents.
|
protected void |
validateTree() |
Recursively descends the container tree and recomputes the
layout for any subtrees marked as needing it (those marked as
invalid).
|
-
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, revalidate, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
Method Detail
-
countComponents
@Deprecated
public int countComponents()
Deprecated. As of JDK version 1.1,
replaced by getComponentCount().
-
getComponentZOrder
public int getComponentZOrder(Component comp)
Returns the z-order index of the component inside the container.
The higher a component is in the z-order hierarchy, the lower
its index. The component with the lowest z-order index is
painted last, above all other child components.
- Parameters:
comp - the component being queried
- Returns:
- the z-order index of the component; otherwise
returns -1 if the component is
null
or doesn't belong to the container
- Since:
- 1.5
- See Also:
setComponentZOrder(java.awt.Component, int)
-
removeAll
public void removeAll()
Removes all the components from this container.
This method also notifies the layout manager to remove the
components from this container's layout via the
removeLayoutComponent method.
This method changes layout-related information, and therefore,
invalidates the component hierarchy. If the container has already been
displayed, the hierarchy must be validated thereafter in order to
reflect the changes.
- See Also:
add(java.awt.Component),
remove(int),
invalidate()
-
validate
public void validate()
Validates this container and all of its subcomponents.
Validating a container means laying out its subcomponents.
Layout-related changes, such as setting the bounds of a component, or
adding a component to the container, invalidate the container
automatically. Note that the ancestors of the container may be
invalidated also (see Component.invalidate() for details.)
Therefore, to restore the validity of the hierarchy, the validate() method should be invoked on the top-most invalid
container of the hierarchy.
Validating the container may be a quite time-consuming operation. For
performance reasons a developer may postpone the validation of the
hierarchy till a set of layout-related operations completes, e.g. after
adding all the children to the container.
If this Container is not valid, this method invokes
the validateTree method and marks this Container
as valid. Otherwise, no action is performed.
- Overrides:
validate in class Component
- See Also:
add(java.awt.Component),
invalidate(),
isValidateRoot(),
JComponent.revalidate(),
validateTree()
-
validateTree
protected void validateTree()
Recursively descends the container tree and recomputes the
layout for any subtrees marked as needing it (those marked as
invalid). Synchronization should be provided by the method
that calls this one: validate.
- See Also:
doLayout(),
validate()
-
getAlignmentX
public float getAlignmentX()
Returns the alignment along the x axis. This specifies how
the component would like to be aligned relative to other
components. The value should be a number between 0 and 1
where 0 represents alignment along the origin, 1 is aligned
the furthest away from the origin, 0.5 is centered, etc.
- Overrides:
getAlignmentX in class Component
-
getAlignmentY
public float getAlignmentY()
Returns the alignment along the y axis. This specifies how
the component would like to be aligned relative to other
components. The value should be a number between 0 and 1
where 0 represents alignment along the origin, 1 is aligned
the furthest away from the origin, 0.5 is centered, etc.
- Overrides:
getAlignmentY in class Component
-
paint
public void paint(Graphics g)
Paints the container. This forwards the paint to any lightweight
components that are children of this container. If this method is
reimplemented, super.paint(g) should be called so that lightweight
components are properly rendered. If a child component is entirely
clipped by the current clipping setting in g, paint() will not be
forwarded to that child.
- Overrides:
paint in class Component
- Parameters:
g - the specified Graphics window
- See Also:
Component.update(Graphics)
-
update
public void update(Graphics g)
Updates the container. This forwards the update to any lightweight
components that are children of this container. If this method is
reimplemented, super.update(g) should be called so that lightweight
components are properly rendered. If a child component is entirely
clipped by the current clipping setting in g, update() will not be
forwarded to that child.
- Overrides:
update in class Component
- Parameters:
g - the specified Graphics window
- See Also:
Component.update(Graphics)
-
print
public void print(Graphics g)
Prints the container. This forwards the print to any lightweight
components that are children of this container. If this method is
reimplemented, super.print(g) should be called so that lightweight
components are properly rendered. If a child component is entirely
clipped by the current clipping setting in g, print() will not be
forwarded to that child.
- Overrides:
print in class Component
- Parameters:
g - the specified Graphics window
- See Also:
Component.update(Graphics)
-
getComponentAt
public Component getComponentAt(int x,
int y)
Locates the component that contains the x,y position. The
top-most child component is returned in the case where there
is overlap in the components. This is determined by finding
the component closest to the index 0 that claims to contain
the given point via Component.contains(), except that Components
which have native peers take precedence over those which do not
(i.e., lightweight Components).
- Overrides:
getComponentAt in class Component
- Parameters:
x - the x coordinate
y - the 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; otherwise the top-most child is returned.
- Since:
- JDK1.1
- See Also:
Component.contains(int, int)
-
removeNotify
public void removeNotify()
Makes this Container undisplayable by removing its connection
to its native screen resource. Making a container undisplayable
will cause all of its children to be made undisplayable.
This method is called by the toolkit internally and should
not be called directly by programs.
- Overrides:
removeNotify in class Component
- See Also:
Component.isDisplayable(),
addNotify()
-
paramString
protected String paramString()
Returns a string representing the state of this Container.
This method is intended to be used only for debugging purposes, and the
content and format of the returned string may vary between
implementations. The returned string may be empty but may not be
null.
- Overrides:
paramString in class Component
- Returns:
- the parameter string of this container
-
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.
- Overrides:
areFocusTraversalKeysSet in class Component
- Parameters:
id - one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or
KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS
- Returns:
true if the the Set of focus traversal keys for the
given focus traversal operation has been explicitly defined for
this Component; false otherwise.
- 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
-
isFocusCycleRoot
public boolean isFocusCycleRoot(Container container)
Returns whether the specified Container is the focus cycle root of this
Container's focus traversal cycle. Each focus traversal cycle has only
a single focus cycle root and each Container which is not a focus cycle
root belongs to only a single focus traversal cycle. Containers which
are focus cycle roots belong to two cycles: one rooted at the Container
itself, and one rooted at the Container's nearest focus-cycle-root
ancestor. This method will return true for both such
Containers in this case.
- Overrides:
isFocusCycleRoot in class Component
- Parameters:
container - the Container to be tested
- Returns:
true if the specified Container is a focus-cycle-
root of this Container; false otherwise
- Since:
- 1.4
- See Also:
isFocusCycleRoot()
-
isFocusTraversalPolicySet
public boolean isFocusTraversalPolicySet()
Returns whether the focus traversal policy has been explicitly set for
this Container. If this method returns false, this
Container will inherit its focus traversal policy from an ancestor.
- Returns:
true if the focus traversal policy has been
explicitly set for this Container; false otherwise.
- Since:
- 1.4
-
isFocusCycleRoot
public boolean isFocusCycleRoot()
Returns whether this Container is the root of a focus traversal cycle.
Once focus enters a traversal cycle, typically it cannot leave it via
focus traversal unless one of the up- or down-cycle keys is pressed.
Normal traversal is limited to this Container, and all of this
Container's descendants that are not descendants of inferior focus
cycle roots. Note that a FocusTraversalPolicy may bend these
restrictions, however. For example, ContainerOrderFocusTraversalPolicy
supports implicit down-cycle traversal.
- Returns:
- whether this Container is the root of a focus traversal cycle
- Since:
- 1.4
- See Also:
setFocusCycleRoot(boolean),
setFocusTraversalPolicy(java.awt.FocusTraversalPolicy),
getFocusTraversalPolicy(),
ContainerOrderFocusTraversalPolicy
-
transferFocusDownCycle
public void transferFocusDownCycle()
Transfers the focus down one focus traversal cycle. If this Container is
a focus cycle root, then the focus owner is set to this Container's
default Component to focus, and the current focus cycle root is set to
this Container. If this Container is not a focus cycle root, then no
focus traversal operation occurs.
- Since:
- 1.4
- See Also:
Component.requestFocus(),
isFocusCycleRoot(java.awt.Container),
setFocusCycleRoot(boolean)
Java™ Platform Standard Ed. 8
Submit a bug or feature For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples. Copyright © 1993, 2026, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
|