All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class java.awt.Component

java.lang.Object
   |
   +----java.awt.Component

public abstract class Component
extends Object
implements ImageObserver, MenuContainer, Serializable
A component is an object having a graphical representation that can be displayed on the screen and that can interact with the user. Examples of components are the buttons, checkboxes, and scrollbars of a typical graphical user interface.

The Component class is the abstract superclass of the nonmenu-related Abstract Window Toolkit components. Class Component can also be extended directly to create a lightweight component. A lightweight component is a component that is not associated with a native opaque window.


Variable Index

 o BOTTOM_ALIGNMENT
Ease-of-use constant for getAlignmentY.
 o CENTER_ALIGNMENT
Ease-of-use constant for getAlignmentY and getAlignmentX.
 o LEFT_ALIGNMENT
Ease-of-use constant for getAlignmentX.
 o RIGHT_ALIGNMENT
Ease-of-use constant for getAlignmentX.
 o TOP_ALIGNMENT
Ease-of-use constant for getAlignmentY().

Constructor Index

 o Component()
Constructs a new component.

Method Index

 o action(Event, Object)
Deprecated.
 o add(PopupMenu)
Adds the specified popup menu to the component.
 o addComponentListener(ComponentListener)
Adds the specified component listener to receive component events from this component.
 o addFocusListener(FocusListener)
Adds the specified focus listener to receive focus events from this component.
 o addKeyListener(KeyListener)
Adds the specified key listener to receive key events from this component.
 o addMouseListener(MouseListener)
Adds the specified mouse listener to receive mouse events from this component.
 o addMouseMotionListener(MouseMotionListener)
Adds the specified mouse motion listener to receive mouse motion events from this component.
 o addNotify()
Notifies this component that it has been added to a container and if a peer is required, it should be created.
 o bounds()
Deprecated.
 o checkImage(Image, ImageObserver)
Returns the status of the construction of a screen representation of the specified image.
 o checkImage(Image, int, int, ImageObserver)
Returns the status of the construction of a screen representation of the specified image.
 o contains(int, int)
Checks whether this component "contains" the specified point, where x and y are defined to be relative to the coordinate system of this component.
 o contains(Point)
Checks whether this component "contains" the specified point, where the point's x and y coordinates are defined to be relative to the coordinate system of this component.
 o createImage(ImageProducer)
Creates an image from the specified image producer.
 o createImage(int, int)
Creates an off-screen drawable image to be used for double buffering.
 o deliverEvent(Event)
Deprecated.
 o disable()
Deprecated.
 o disableEvents(long)
Disables the events defined by the specified event mask parameter from being delivered to this component.
 o dispatchEvent(AWTEvent)
Dispatches an event to this component or one of its sub components.
 o doLayout()
Prompts the layout manager to lay out this component.
 o enable()
Deprecated.
 o enable(boolean)
Deprecated.
 o enableEvents(long)
Enables the events defined by the specified event mask parameter to be delivered to this component.
 o getAlignmentX()
Returns the alignment along the x axis.
 o getAlignmentY()
Returns the alignment along the y axis.
 o getBackground()
Gets the background color of this component.
 o getBounds()
Gets the bounds of this component in the form of a Rectangle object.
 o getColorModel()
Gets the instance of ColorModel used to display the component on the output device.
 o getComponentAt(int, int)
Determines if this component or one of its immediate subcomponents contains the (xy) location, and if so, returns the containing component.
 o getComponentAt(Point)
Returns the component or subcomponent that contains the specified point.
 o getCursor()
Gets the cursor set on this component.
 o getFont()
Gets the font of this component.
 o getFontMetrics(Font)
Gets the font metrics for the specified font.
 o getForeground()
Gets the foreground color of this component.
 o getGraphics()
Creates a graphics context for this component.
 o getLocale()
Gets the locale of this component.
 o getLocation()
Gets the location of this component in the form of a point specifying the component's top-left corner.
 o getLocationOnScreen()
Gets the location of this component in the form of a point specifying the component's top-left corner in the screen's coordinate space.
 o getMaximumSize()
Gets the maximum size of this component.
 o getMinimumSize()
Gets the mininimum size of this component.
 o getName()
Gets the name of the component.
 o getParent()
Gets the parent of this component.
 o getPeer()
Deprecated.
 o getPreferredSize()
Gets the preferred size of this component.
 o getSize()
Returns the size of this component in the form of a Dimension object.
 o getToolkit()
Gets the toolkit of this component.
 o getTreeLock()
Gets this component's locking object (the object that owns the thread sychronization monitor) for AWT component-tree and layout operations.
 o gotFocus(Event, Object)
Deprecated.
 o handleEvent(Event)
Deprecated.
 o hide()
Deprecated.
 o imageUpdate(Image, int, int, int, int, int)
Repaints the component when the image has changed.
 o inside(int, int)
Deprecated.
 o invalidate()
Invalidates this component.
 o isEnabled()
Determines whether this component is enabled.
 o isFocusTraversable()
Returns the value of a flag that indicates whether this component can be traversed using Tab or Shift-Tab keyboard focus traversal.
 o isShowing()
Determines whether this component is showing on screen.
 o isValid()
Determines whether this component is valid.
 o isVisible()
Determines whether this component is visible.
 o keyDown(Event, int)
Deprecated.
 o keyUp(Event, int)
Deprecated.
 o layout()
Deprecated.
 o list()
Prints a listing of this component to the standard system output stream System.out.
 o list(PrintStream)
Prints a listing of this component to the specified output stream.
 o list(PrintStream, int)
Prints out a list, starting at the specified indention, to the specified print stream.
 o list(PrintWriter)
Prints a listing to the specified print writer.
 o list(PrintWriter, int)
Prints out a list, starting at the specified indention, to the specified print writer.
 o locate(int, int)
Deprecated.
 o location()
Deprecated.
 o lostFocus(Event, Object)
Deprecated.
 o minimumSize()
Deprecated.
 o mouseDown(Event, int, int)
Deprecated.
 o mouseDrag(Event, int, int)
Deprecated.
 o mouseEnter(Event, int, int)
Deprecated.
 o mouseExit(Event, int, int)
Deprecated.
 o mouseMove(Event, int, int)
Deprecated.
 o mouseUp(Event, int, int)
Deprecated.
 o move(int, int)
Deprecated.
 o nextFocus()
Deprecated.
 o paint(Graphics)
Paints this component.
 o paintAll(Graphics)
Paints this component and all of its subcomponents.
 o paramString()
Returns the parameter string representing the state of this component.
 o postEvent(Event)
Deprecated.
 o preferredSize()
Deprecated.
 o prepareImage(Image, ImageObserver)
Prepares an image for rendering on this component.
 o prepareImage(Image, int, int, ImageObserver)
Prepares an image for rendering on this component at the specified width and height.
 o print(Graphics)
Prints this component.
 o printAll(Graphics)
Prints this component and all of its subcomponents.
 o processComponentEvent(ComponentEvent)
Processes component events occurring on this component by dispatching them to any registered ComponentListener objects.
 o processEvent(AWTEvent)
Processes events occurring on this component.
 o processFocusEvent(FocusEvent)
Processes focus events occurring on this component by dispatching them to any registered FocusListener objects.
 o processKeyEvent(KeyEvent)
Processes key events occurring on this component by dispatching them to any registered objects.
 o processMouseEvent(MouseEvent)
Processes mouse events occurring on this component by dispatching them to any registered MouseListener objects.
 o processMouseMotionEvent(MouseEvent)
Processes mouse motion events occurring on this component by dispatching them to any registered MouseMotionListener objects.
 o remove(MenuComponent)
Removes the specified popup menu from the component.
 o removeComponentListener(ComponentListener)
Removes the specified component listener so that it no longer receives component events from this component.
 o removeFocusListener(FocusListener)
Removes the specified focus listener so that it no longer receives focus events from this component.
 o removeKeyListener(KeyListener)
Removes the specified key listener so that it no longer receives key events from this component.
 o removeMouseListener(MouseListener)
Removes the specified mouse listener so that it no longer receives mouse events from this component.
 o removeMouseMotionListener(MouseMotionListener)
Removes the specified mouse motion listener so that it no longer receives mouse motion events from this component.
 o removeNotify()
Notifies this component that it has been removed from its container and if a peers exists, it destroys it.
 o repaint()
Repaints this component.
 o repaint(int, int, int, int)
Repaints the specified rectangle of this component.
 o repaint(long)
Repaints the component.
 o repaint(long, int, int, int, int)
Repaints the specified rectangle of this component within tm milliseconds.
 o requestFocus()
Requests that this component get the input focus.
 o reshape(int, int, int, int)
Deprecated.
 o resize(Dimension)
Deprecated.
 o resize(int, int)
Deprecated.
 o setBackground(Color)
Sets the background color of this component.
 o setBounds(int, int, int, int)
Moves and resizes this component.
 o setBounds(Rectangle)
Moves and resizes this component to conform to the new bounding rectangle r.
 o setCursor(Cursor)
Set the cursor image to a predefined cursor.
 o setEnabled(boolean)
Enables or disables this component, depending on the value of the parameter b.
 o setFont(Font)
Sets the font of this component.
 o setForeground(Color)
Sets the foreground color of this component.
 o setLocale(Locale)
Sets the locale of this component.
 o setLocation(int, int)
Moves this component to a new location.
 o setLocation(Point)
Moves this component to a new location.
 o setName(String)
Sets the name of the component to the specified string.
 o setSize(Dimension)
Resizes this component so that it has width d.width and height d.height.
 o setSize(int, int)
Resizes this component so that it has width width and height.
 o setVisible(boolean)
Shows or hides this component depending on the value of parameter b.
 o show()
Deprecated.
 o show(boolean)
Deprecated.
 o size()
Deprecated.
 o toString()
Returns a string representation of this component and its values.
 o transferFocus()
Transfers the focus to the next component.
 o update(Graphics)
Updates this component.
 o validate()
Ensures that this component has a valid layout.

Variables

 o TOP_ALIGNMENT
 public static final float TOP_ALIGNMENT
Ease-of-use constant for getAlignmentY(). Specifies an alignment to the top of the component.

See Also:
getAlignmentY
 o CENTER_ALIGNMENT
 public static final float CENTER_ALIGNMENT
Ease-of-use constant for getAlignmentY and getAlignmentX. Specifies an alignment to the center of the component

See Also:
getAlignmentX, getAlignmentY
 o BOTTOM_ALIGNMENT
 public static final float BOTTOM_ALIGNMENT
Ease-of-use constant for getAlignmentY. Specifies an alignment to the bottom of the component.

See Also:
getAlignmentY
 o LEFT_ALIGNMENT
 public static final float LEFT_ALIGNMENT
Ease-of-use constant for getAlignmentX. Specifies an alignment to the left side of the component.

See Also:
getAlignmentX
 o RIGHT_ALIGNMENT
 public static final float RIGHT_ALIGNMENT
Ease-of-use constant for getAlignmentX. Specifies an alignment to the right side of the component.

See Also:
getAlignmentX

Constructors

 o Component
 protected Component()
Constructs a new component. Class Component can be extended directly to create a lightweight component that does not utilize an opaque native window. A lightweight component must be hosted by a native container somewhere higher up in the component tree (for example, by a Frame object).

Methods

 o getName
 public String getName()
Gets the name of the component.

Returns:
This component's name.
See Also:
setName
 o setName
 public void setName(String name)
Sets the name of the component to the specified string.

Parameters:
name - The string that is to be this component's name.
See Also:
getName
 o getParent
 public Container getParent()
Gets the parent of this component.

Returns:
The parent container of this component.
 o getPeer
 public ComponentPeer getPeer()
Note: getPeer() is deprecated. As of JDK version 1.1, programs should not directly manipulate peers.

 o getTreeLock
 public final Object getTreeLock()
Gets this component's locking object (the object that owns the thread sychronization monitor) for AWT component-tree and layout operations.

Returns:
This component's locking object.
 o getToolkit
 public Toolkit getToolkit()
Gets the toolkit of this component. Note that the frame that contains a component controls which toolkit is used by that component. Therefore if the component is moved from one frame to another, the toolkit it uses may change.

Returns:
The toolkit of this component.
 o isValid
 public boolean isValid()
Determines whether this component is valid. Components are invalidated when they are first shown on the screen.

Returns:
true if the component is valid; false otherwise.
See Also:
validate, invalidate
 o isVisible
 public boolean isVisible()
Determines whether this component is visible. Components are initially visible, with the exception of top level components such as Frame objects.

Returns:
true if the component is visible; false otherwise.
See Also:
setVisible
 o isShowing
 public boolean isShowing()
Determines whether this component is showing on screen. This means that the component must be visible, and it must be in a container that is visible and showing.

Returns:
true if the component is showing; false otherwise.
See Also:
setVisible
 o isEnabled
 public boolean isEnabled()
Determines whether this component is enabled. An enabled component can respond to user input and generate events. Components are enabled initially by default. A component may be enabled or disabled by calling its setEnabled method.

Returns:
true if the component is enabled; false otherwise.
See Also:
setEnabled
 o setEnabled
 public void setEnabled(boolean b)
Enables or disables this component, depending on the value of the parameter b. An enabled component can respond to user input and generate events. Components are enabled initially by default.

Parameters:
b - If true, this component is enabled; otherwise this component is disabled.
See Also:
isEnabled
 o enable
 public void enable()
Note: enable() is deprecated. As of JDK version 1.1, replaced by setEnabled(boolean).

 o enable
 public void enable(boolean b)
Note: enable() is deprecated. As of JDK version 1.1, replaced by setEnabled(boolean).

 o disable
 public void disable()
Note: disable() is deprecated. As of JDK version 1.1, replaced by setEnabled(boolean).

 o setVisible
 public void setVisible(boolean b)
Shows or hides this component depending on the value of parameter b.

Parameters:
b - If true, shows this component; otherwise, hides this component.
See Also:
isVisible
 o show
 public void show()
Note: show() is deprecated. As of JDK version 1.1, replaced by setVisible(boolean).

 o show
 public void show(boolean b)
Note: show() is deprecated. As of JDK version 1.1, replaced by setVisible(boolean).

 o hide
 public void hide()
Note: hide() is deprecated. As of JDK version 1.1, replaced by setVisible(boolean).

 o getForeground
 public Color getForeground()
Gets the foreground color of this component.

Returns:
This component's foreground color. If this component does not have a foreground color, the foreground color of its parent is returned.
See Also:
java.awt.Component#setForeground
 o setForeground
 public void setForeground(Color c)
Sets the foreground color of this component.

Parameters:
c - The color to become this component's foreground color.
See Also:
getForeground
 o getBackground
 public Color getBackground()
Gets the background color of this component.

Returns:
This component's background color. If this component does not have a background color, the background color of its parent is returned.
See Also:
setBackground
 o setBackground
 public void setBackground(Color c)
Sets the background color of this component.

Parameters:
c - The color to become this component's background color.
See Also:
getBackground
 o getFont
 public Font getFont()
Gets the font of this component.

Returns:
This component's font. If a font has not been set for this component, the font of its parent is returned.
See Also:
setFont
 o setFont
 public void setFont(Font f)
Sets the font of this component.

Parameters:
f - The font to become this component's font.
See Also:
getFont
 o getLocale
 public Locale getLocale()
Gets the locale of this component.

Returns:
This component's locale. If this component does not have a locale, the locale of its parent is returned.
Throws: IllegalComponentStateException
If the Component does not have its own locale and has not yet been added to a containment hierarchy such that the locale can be determined from the containing parent.
See Also:
setLocale
 o setLocale
 public void setLocale(Locale l)
Sets the locale of this component.

Parameters:
l - The locale to become this component's locale.
See Also:
getLocale
 o getColorModel
 public ColorModel getColorModel()
Gets the instance of ColorModel used to display the component on the output device.

Returns:
The color model used by this component.
See Also:
ColorModel, getColorModel, getColorModel
 o getLocation
 public Point getLocation()
Gets the location of this component in the form of a point specifying the component's top-left corner. The location will be relative to the parent's coordinate space.

Returns:
An instance of Point representing the top-left corner of the component's bounds in the coordinate space of the component's parent.
See Also:
setLocation, getLocationOnScreen
 o getLocationOnScreen
 public Point getLocationOnScreen()
Gets the location of this component in the form of a point specifying the component's top-left corner in the screen's coordinate space.

Returns:
An instance of Point representing the top-left corner of the component's bounds in the coordinate space of the screen.
See Also:
setLocation, getLocation
 o location
 public Point location()
Note: location() is deprecated. As of JDK version 1.1, replaced by getLocation().

 o setLocation
 public void setLocation(int x,
                         int y)
Moves this component to a new location. The top-left corner of the new location is specified by the x and y parameters in the coordinate space of this component's parent.

Parameters:
x - The x-coordinate of the new location's top-left corner in the parent's coordinate space.
y - The y-coordinate of the new location's top-left corner in the parent's coordinate space.
See Also:
getLocation, setBounds
 o move
 public void move(int x,
                  int y)
Note: move() is deprecated. As of JDK version 1.1, replaced by setLocation(int, int).

 o setLocation
 public void setLocation(Point p)
Moves this component to a new location. The top-left corner of the new location is specified by point p. Point p is given in the parent's coordinate space.

Parameters:
p - The point defining the top-left corner of the new location, given in the coordinate space of this component's parent.
See Also:
getLocation, setBounds
 o getSize
 public Dimension getSize()
Returns the size of this component in the form of a Dimension object. The height field of the Dimension object contains this component's height, and the width field of the Dimension object contains this component's width.

Returns:
A Dimension object that indicates the size of this component.
See Also:
setSize
 o size
 public Dimension size()
Note: size() is deprecated. As of JDK version 1.1, replaced by getSize().

 o setSize
 public void setSize(int width,
                     int height)
Resizes this component so that it has width width and height.

Parameters:
width - The new width of this component in pixels.
height - The new height of this component in pixels.
See Also:
getSize, setBounds
 o resize
 public void resize(int width,
                    int height)
Note: resize() is deprecated. As of JDK version 1.1, replaced by setSize(int, int).

 o setSize
 public void setSize(Dimension d)
Resizes this component so that it has width d.width and height d.height.

Parameters:
d - The dimension specifying the new size of this component.
See Also:
setSize, setBounds
 o resize
 public void resize(Dimension d)
Note: resize() is deprecated. As of JDK version 1.1, replaced by setSize(Dimension).

 o getBounds
 public Rectangle getBounds()
Gets the bounds of this component in the form of a Rectangle object. The bounds specify this component's width, height, and location relative to its parent.

Returns:
A rectangle indicating this component's bounds.
See Also:
setBounds, getLocation, getSize
 o bounds
 public Rectangle bounds()
Note: bounds() is deprecated. As of JDK version 1.1, replaced by getBounds().

 o setBounds
 public void setBounds(int x,
                       int y,
                       int width,
                       int height)
Moves and resizes this component. The new location of the top-left corner is specified by x and y, and the new size is specified by width and height.

Parameters:
x - The new x-coordinate of this component.
y - The new y-coordinate of this component.
width - The new width of this component.
height - The new height of this component.
See Also:
getBounds, setLocation, setLocation, setSize, setSize
 o reshape
 public void reshape(int x,
                     int y,
                     int width,
                     int height)
Note: reshape() is deprecated. As of JDK version 1.1, replaced by setBounds(int, int, int, int).

 o setBounds
 public void setBounds(Rectangle r)
Moves and resizes this component to conform to the new bounding rectangle r. This component's new position is specified by r.x and r.y, and its new size is specified by r.width and r.height

Parameters:
r - The new bounding rectangle for this component.
See Also:
getBounds, setLocation, setLocation, setSize, setSize
 o getPreferredSize
 public Dimension getPreferredSize()
Gets the preferred size of this component.

Returns:
A dimension object indicating this component's preferred size.
See Also:
getMinimumSize, LayoutManager
 o preferredSize
 public Dimension preferredSize()
Note: preferredSize() is deprecated. As of JDK version 1.1, replaced by getPreferredSize().

 o getMinimumSize
 public Dimension getMinimumSize()
Gets the mininimum size of this component.

Returns:
A dimension object indicating this component's minimum size.
See Also:
getPreferredSize, awtLayoutManager
 o minimumSize
 public Dimension minimumSize()
Note: minimumSize() is deprecated. As of JDK version 1.1, replaced by getMinimumSize().

 o getMaximumSize
 public Dimension getMaximumSize()
Gets the maximum size of this component.

Returns:
A dimension object indicating this component's maximum size.
See Also:
getMinimumSize, getPreferredSize, LayoutManager
 o 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.

 o 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.

 o doLayout
 public void doLayout()
Prompts the layout manager to lay out this component. This is usually called when the component (more specifically, container) is validated.

See Also:
validate, LayoutManager
 o layout
 public void layout()
Note: layout() is deprecated. As of JDK version 1.1, replaced by doLayout().

 o validate
 public void validate()
Ensures that this component has a valid layout. This method is primarily intended to operate on instances of Container.

See Also:
invalidate, doLayout, LayoutManager, validate
 o invalidate
 public void invalidate()
Invalidates this component. This component and all parents above it are marked as needing to be laid out. This method can be called often, so it needs to execute quickly.

See Also:
validate, doLayout, LayoutManager
 o getGraphics
 public Graphics getGraphics()
Creates a graphics context for this component. This method will return null if this component is currently not on the screen.

Returns:
A graphics context for this component, or null if it has none.
See Also:
paint
 o getFontMetrics
 public FontMetrics getFontMetrics(Font font)
Gets the font metrics for the specified font.

Parameters:
font - The font for which font metrics is to be obtained.
font - the font.
Returns:
The font metrics for font.
See Also:
getFont, getPeer, getFontMetrics, getFontMetrics
 o setCursor
 public synchronized void setCursor(Cursor cursor)
Set the cursor image to a predefined cursor.

Parameters:
cursor - One of the constants defined by the Cursor class. If this parameter is null then this component will inherit the cursor of its parent.
See Also:
getCursor, Cursor
 o getCursor
 public Cursor getCursor()
Gets the cursor set on this component.

Returns:
The cursor for this component.
See Also:
setCursor, Cursor
 o paint
 public void paint(Graphics g)
Paints this component. This method is called when the contents of the component should be painted in response to the component first being shown or damage needing repair. The clip rectangle in the Graphics parameter will be set to the area which needs to be painted.

Parameters:
g - The graphics context to use for painting.
See Also:
update
 o update
 public void update(Graphics g)
Updates this component.

The AWT calls the update method in response to a call to repaintupdate or paint. You can assume that the background is not cleared.

The updatemethod of Component does the following:

  • Clears this component by filling it with the background color.
  • Sets the color of the graphics context to be the foreground color of this component.
  • Calls this component's paint method to completely redraw this component.

The origin of the graphics context, its (00) coordinate point, is the top-left corner of this component. The clipping region of the graphics context is the bounding rectangle of this component.

Parameters:
g - the specified context to use for updating.
See Also:
paint, repaint
 o paintAll
 public void paintAll(Graphics g)
Paints this component and all of its subcomponents.

The origin of the graphics context, its (00) coordinate point, is the top-left corner of this component. The clipping region of the graphics context is the bounding rectangle of this component.

Parameters:
g - the graphics context to use for painting.
See Also:
paint
 o repaint
 public void repaint()
Repaints this component.

This method causes a call to this component's update method as soon as possible.

See Also:
update
 o repaint
 public void repaint(long tm)
Repaints the component. This will result in a call to update within tm milliseconds.

Parameters:
tm - maximum time in milliseconds before update
See Also:
paint, update
 o repaint
 public void repaint(int x,
                     int y,
                     int width,
                     int height)
Repaints the specified rectangle of this component.

This method causes a call to this component's update method as soon as possible.

Parameters:
x - the x coordinate.
y - the y coordinate.
width - the width.
height - the height.
See Also:
update
 o repaint
 public void repaint(long tm,
                     int x,
                     int y,
                     int width,
                     int height)
Repaints the specified rectangle of this component within tm milliseconds.

This method causes a call to this component's update method.

Parameters:
tm - maximum time in milliseconds before update.
x - the x coordinate.
y - the y coordinate.
width - the width.
height - the height.
See Also:
update
 o print
 public void print(Graphics g)
Prints this component. Applications should override this method for components that must do special processing before being printed or should be printed differently than they are painted.

The default implementation of this method calls the paint method.

The origin of the graphics context, its (00) coordinate point, is the top-left corner of this component. The clipping region of the graphics context is the bounding rectangle of this component.

Parameters:
g - the graphics context to use for printing.
See Also:
paint
 o printAll
 public void printAll(Graphics g)
Prints this component and all of its subcomponents.

The origin of the graphics context, its (00) coordinate point, is the top-left corner of this component. The clipping region of the graphics context is the bounding rectangle of this component.

Parameters:
g - the graphics context to use for printing.
See Also:
print
 o imageUpdate
 public boolean imageUpdate(Image img,
                            int flags,
                            int x,
                            int y,
                            int w,
                            int h)
Repaints the component when the image has changed. This imageUpdate method of an ImageObserver is called when more information about an image which had been previously requested using an asynchronous routine such as the drawImage method of Graphics becomes available. See the definition of imageUpdate for more information on this method and its arguments.

The imageUpdate method of Component incrementally draws an image on the component as more of the bits of the image are available.

If the system property awt.image.incrementalDraw is missing or has the value true, the image is incrementally drawn, If the system property has any other value, then the image is not drawn until it has been completely loaded.

Also, if incremental drawing is in effect, the value of the system property awt.image.redrawrate is interpreted as an integer to give the maximum redraw rate, in milliseconds. If the system property is missing or cannot be interpreted as an integer, the redraw rate is once every 100ms.

The interpretation of the x, y, width, and height arguments depends on the value of the infoflags argument.

Parameters:
img - the image being observed.
infoflags - see imageUpdate for more information.
x - the x coordinate.
y - the y coordinate.
width - the width.
height - the height.
Returns:
true if the flags indicate that the image is completely loaded; false otherwise.
See Also:
ImageObserver, drawImage, drawImage, drawImage, drawImage, imageUpdate
 o createImage
 public Image createImage(ImageProducer producer)
Creates an image from the specified image producer.

Parameters:
producer - the image producer
Returns:
the image produced.
 o createImage
 public Image createImage(int width,
                          int height)
Creates an off-screen drawable image to be used for double buffering.

Parameters:
width - the specified width.
height - the specified height.
Returns:
an off-screen drawable image, which can be used for double buffering.
 o prepareImage
 public boolean prepareImage(Image image,
                             ImageObserver observer)
Prepares an image for rendering on this component. The image data is downloaded asynchronously in another thread and the appropriate screen representation of the image is generated.

Parameters:
image - the Image for which to prepare a screen representation.
observer - the ImageObserver object to be notified as the image is being prepared.
Returns:
true if the image has already been fully prepared; false otherwise.
 o prepareImage
 public boolean prepareImage(Image image,
                             int width,
                             int height,
                             ImageObserver observer)
Prepares an image for rendering on this component at the specified width and height.

The image data is downloaded asynchronously in another thread, and an appropriately scaled screen representation of the image is generated.

Parameters:
image - the instance of Image for which to prepare a screen representation.
width - the width of the desired screen representation.
height - the height of the desired screen representation.
observer - the ImageObserver object to be notified as the image is being prepared.
Returns:
true if the image has already been fully prepared; false otherwise.
See Also:
ImageObserver
 o checkImage
 public int checkImage(Image image,
                       ImageObserver observer)
Returns the status of the construction of a screen representation of the specified image.

This method does not cause the image to begin loading. An application must use the prepareImage method to force the loading of an image.

Information on the flags returned by this method can be found with the discussion of the ImageObserver interface.

Parameters:
image - the Image object whose status is being checked.
observer - the ImageObserver object to be notified as the image is being prepared.
Returns:
the bitwise inclusive OR of ImageObserver flags indicating what information about the image is currently available.
See Also:
prepareImage, checkImage, ImageObserver
 o checkImage
 public int checkImage(Image image,
                       int width,
                       int height,
                       ImageObserver observer)
Returns the status of the construction of a screen representation of the specified image.

This method does not cause the image to begin loading. An application must use the prepareImage method to force the loading of an image.

The checkImage method of Component calls its peer's checkImage method to calculate the flags. If this component does not yet have a peer, the component's toolkit's checkImage method is called instead.

Information on the flags returned by this method can be found with the discussion of the ImageObserver interface.

Parameters:
image - the Image object whose status is being checked.
width - the width of the scaled version whose status is to be checked.
height - the height of the scaled version whose status is to be checked.
observer - the ImageObserver object to be notified as the image is being prepared.
Returns:
the bitwise inclusive OR of ImageObserver flags indicating what information about the image is currently available.
See Also:
prepareImage, checkImage, _top_
 o contains
 public boolean contains(int x,
                         int y)
Checks whether this component "contains" the specified point, where x and y are defined to be relative to the coordinate system of this component.

Parameters:
x - the x coordinate of the point.
y - the y coordinate of the point.
See Also:
getComponentAt
 o inside
 public boolean inside(int x,
                       int y)
Note: inside() is deprecated. As of JDK version 1.1, replaced by contains(int, int).

 o contains
 public boolean contains(Point p)
Checks whether this component "contains" the specified point, where the point's x and y coordinates are defined to be relative to the coordinate system of this component.

Parameters:
p - the point.
See Also:
getComponentAt
 o getComponentAt
 public Component getComponentAt(int x,
                                 int y)
Determines if this component or one of its immediate subcomponents contains the (xy) location, and if so, returns the containing component. This method only looks one level deep. If the point (xy) is inside a subcomponent that itself has subcomponents, it does not go looking down the subcomponent tree.

The locate method of Component simply returns the component itself if the (xy) coordinate location is inside its bounding box, and null otherwise.

Parameters:
x - the x coordinate.
y - the y coordinate.
Returns:
the component or subcomponent that contains the (xy) location; null if the location is outside this component.
See Also:
contains
 o locate
 public Component locate(int x,
                         int y)
Note: locate() is deprecated. As of JDK version 1.1, replaced by getComponentAt(int, int).

 o getComponentAt
 public Component getComponentAt(Point p)
Returns the component or subcomponent that contains the specified point.

Parameters:
p - the point.
See Also:
contains
 o deliverEvent
 public void deliverEvent(Event e)
Note: deliverEvent() is deprecated. As of JDK version 1.1, replaced by dispatchEvent(AWTEvent e).

 o dispatchEvent
 public final void dispatchEvent(AWTEvent e)
Dispatches an event to this component or one of its sub components.

Parameters:
e - the event
 o postEvent
 public boolean postEvent(Event e)
Note: postEvent() is deprecated. As of JDK version 1.1, replaced by dispatchEvent(AWTEvent).

 o addComponentListener
 public synchronized void addComponentListener(ComponentListener l)
Adds the specified component listener to receive component events from this component.

Parameters:
l - the component listener.
See Also:
ComponentEvent, ComponentListener, removeComponentListener
 o removeComponentListener
 public synchronized void removeComponentListener(ComponentListener l)
Removes the specified component listener so that it no longer receives component events from this component.

Parameters:
l - the component listener.
See Also:
ComponentEvent, ComponentListener, addComponentListener
 o addFocusListener
 public synchronized void addFocusListener(FocusListener l)
Adds the specified focus listener to receive focus events from this component.

Parameters:
l - the focus listener.
See Also:
FocusEvent, FocusListener, removeFocusListener
 o removeFocusListener
 public synchronized void removeFocusListener(FocusListener l)
Removes the specified focus listener so that it no longer receives focus events from this component.

Parameters:
l - the focus listener.
See Also:
FocusEvent, FocusListener, addFocusListener
 o addKeyListener
 public synchronized void addKeyListener(KeyListener l)
Adds the specified key listener to receive key events from this component.

Parameters:
l - the key listener.
See Also:
KeyEvent, KeyListener, removeKeyListener
 o removeKeyListener
 public synchronized void removeKeyListener(KeyListener l)
Removes the specified key listener so that it no longer receives key events from this component.

Parameters:
l - the key listener.
See Also:
KeyEvent, KeyListener, addKeyListener
 o addMouseListener
 public synchronized void addMouseListener(MouseListener l)
Adds the specified mouse listener to receive mouse events from this component.

Parameters:
l - the mouse listener.
See Also:
MouseEvent, MouseListener, removeMouseListener
 o removeMouseListener
 public synchronized void removeMouseListener(MouseListener l)
Removes the specified mouse listener so that it no longer receives mouse events from this component.

Parameters:
l - the mouse listener.
See Also:
MouseEvent, MouseListener, addMouseListener
 o addMouseMotionListener
 public synchronized void addMouseMotionListener(MouseMotionListener l)
Adds the specified mouse motion listener to receive mouse motion events from this component.

Parameters:
l - the mouse motion listener.
See Also:
MouseMotionEvent, MouseMotionListener, removeMouseMotionListener
 o removeMouseMotionListener
 public synchronized void removeMouseMotionListener(MouseMotionListener l)
Removes the specified mouse motion listener so that it no longer receives mouse motion events from this component.

Parameters:
l - the mouse motion listener.
See Also:
MouseMotionEvent, MouseMotionListener, addMouseMotionListener
 o enableEvents
 protected final void enableEvents(long eventsToEnable)
Enables the events defined by the specified event mask parameter to be delivered to this component.

Event types are automatically enabled when a listener for that event type is added to the component.

This method only needs to be invoked by subclasses of Component which desire to have the specified event types delivered to processEvent regardless of whether or not a listener is registered.

Parameters:
eventsToEnable - the event mask defining the event types.
See Also:
processEvent, disableEvents
 o disableEvents
 protected final void disableEvents(long eventsToDisable)
Disables the events defined by the specified event mask parameter from being delivered to this component.

Parameters:
eventsToDisable - the event mask defining the event types
See Also:
enableEvents
 o processEvent
 protected void processEvent(AWTEvent e)
Processes events occurring on this component. By default this method calls the appropriate process<event type>Event method for the given class of event.

Parameters:
e - the event.
See Also:
processComponentEvent, processFocusEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent
 o processComponentEvent
 protected void processComponentEvent(ComponentEvent e)
Processes component events occurring on this component by dispatching them to any registered ComponentListener objects.

This method is not called unless component events are enabled for this component. Component events are enabled when one of the following occurs:

  • A ComponentListener object is registered via addComponentListener.
  • Component events are enabled via enableEvents.

Parameters:
e - the component event.
See Also:
ComponentEvent, ComponentListener, addComponentListener, enableEvents
 o processFocusEvent
 protected void processFocusEvent(FocusEvent e)
Processes focus events occurring on this component by dispatching them to any registered FocusListener objects.

This method is not called unless focus events are enabled for this component. Focus events are enabled when one of the following occurs:

  • A FocusListener object is registered via addFocusListener.
  • Focus events are enabled via enableEvents.

Parameters:
e - the focus event.
See Also:
FocusEvent, FocusListener, addFocusListener, enableEvents
 o processKeyEvent
 protected void processKeyEvent(KeyEvent e)
Processes key events occurring on this component by dispatching them to any registered objects.

This method is not called unless key events are enabled for this component. Key events are enabled when one of the following occurs:

  • A KeyListener object is registered via addKeyListener.
  • Key events are enabled via enableEvents.

Parameters:
e - the key event.
See Also:
KeyEvent, KeyListener, addKeyListener, enableEvents
 o processMouseEvent
 protected void processMouseEvent(MouseEvent e)
Processes mouse events occurring on this component by dispatching them to any registered MouseListener objects.

This method is not called unless mouse events are enabled for this component. Mouse events are enabled when one of the following occurs:

  • A MouseListener object is registered via addMouseListener.
  • Mouse events are enabled via enableEvents.

Parameters:
e - the mouse event.
See Also:
MouseEvent, MouseListener, addMouseListener, enableEvents
 o processMouseMotionEvent
 protected void processMouseMotionEvent(MouseEvent e)
Processes mouse motion events occurring on this component by dispatching them to any registered MouseMotionListener objects.

This method is not called unless mouse motion events are enabled for this component. Mouse motion events are enabled when one of the following occurs:

  • A MouseMotionListener object is registered via addMouseMotionListener.
  • Mouse motion events are enabled via enableEvents.

Parameters:
e - the mouse motion event.
See Also:
MouseMotionEvent, MouseMotionListener, addMouseMotionListener, enableEvents
 o handleEvent
 public boolean handleEvent(Event evt)
Note: handleEvent() is deprecated. As of JDK version 1.1 replaced by processEvent(AWTEvent).

 o mouseDown
 public boolean mouseDown(Event evt,
                          int x,
                          int y)
Note: mouseDown() is deprecated. As of JDK version 1.1, replaced by processMouseEvent(MouseEvent).

 o mouseDrag
 public boolean mouseDrag(Event evt,
                          int x,
                          int y)
Note: mouseDrag() is deprecated. As of JDK version 1.1, replaced by processMouseMotionEvent(MouseEvent).

 o mouseUp
 public boolean mouseUp(Event evt,
                        int x,
                        int y)
Note: mouseUp() is deprecated. As of JDK version 1.1, replaced by processMouseEvent(MouseEvent).

 o mouseMove
 public boolean mouseMove(Event evt,
                          int x,
                          int y)
Note: mouseMove() is deprecated. As of JDK version 1.1, replaced by processMouseMotionEvent(MouseEvent).

 o mouseEnter
 public boolean mouseEnter(Event evt,
                           int x,
                           int y)
Note: mouseEnter() is deprecated. As of JDK version 1.1, replaced by processMouseEvent(MouseEvent).

 o mouseExit
 public boolean mouseExit(Event evt,
                          int x,
                          int y)
Note: mouseExit() is deprecated. As of JDK version 1.1, replaced by processMouseEvent(MouseEvent).

 o keyDown
 public boolean keyDown(Event evt,
                        int key)
Note: keyDown() is deprecated. As of JDK version 1.1, replaced by processKeyEvent(KeyEvent).

 o keyUp
 public boolean keyUp(Event evt,
                      int key)
Note: keyUp() is deprecated. As of JDK version 1.1, replaced by processKeyEvent(KeyEvent).

 o action
 public boolean action(Event evt,
                       Object what)
Note: action() is deprecated. As of JDK version 1.1, should register this component as ActionListener on component which fires action events.

 o addNotify
 public void addNotify()
Notifies this component that it has been added to a container and if a peer is required, it should be created. This method should be called by Container.add, and not by user code directly.

See Also:
removeNotify
 o removeNotify
 public void removeNotify()
Notifies this component that it has been removed from its container and if a peers exists, it destroys it. This method should be called by Container.remove, and not by user code directly.

See Also:
addNotify
 o gotFocus
 public boolean gotFocus(Event evt,
                         Object what)
Note: gotFocus() is deprecated. As of JDK version 1.1, replaced by processFocusEvent(FocusEvent).

 o lostFocus
 public boolean lostFocus(Event evt,
                          Object what)
Note: lostFocus() is deprecated. As of JDK version 1.1, replaced by processFocusEvent(FocusEvent).

 o isFocusTraversable
 public boolean isFocusTraversable()
Returns the value of a flag that indicates whether this component can be traversed using Tab or Shift-Tab keyboard focus traversal. If this method returns "false", this component may still request the keyboard focus using requestFocus(), but it will not automatically be assigned focus during tab traversal.

Returns:
true if this component is focus-traverable; false otherwise.
 o requestFocus
 public void requestFocus()
Requests that this component get the input focus.

This component's gotFocus method is called when this method is successful. The component must be visible on the screen for this request to be granted

See Also:
FocusEvent, addFocusListener, processFocusEvent, isFocusTraversable
 o transferFocus
 public void transferFocus()
Transfers the focus to the next component.

See Also:
requestFocus, gotFocus
 o nextFocus
 public void nextFocus()
Note: nextFocus() is deprecated. As of JDK version 1.1, replaced by transferFocus().

 o add
 public synchronized void add(PopupMenu popup)
Adds the specified popup menu to the component.

Parameters:
popup - the popup menu to be added to the component.
See Also:
remove
 o remove
 public synchronized void remove(MenuComponent popup)
Removes the specified popup menu from the component.

Parameters:
popup - the popup menu to be removed.
See Also:
add
 o paramString
 protected String paramString()
Returns the parameter string representing the state of this component. This string is useful for debugging.

Returns:
the parameter string of this component.
 o toString
 public String toString()
Returns a string representation of this component and its values.

Returns:
a string representation of this component.
Overrides:
toString in class Object
 o list
 public void list()
Prints a listing of this component to the standard system output stream System.out.

See Also:
out
 o list
 public void list(PrintStream out)
Prints a listing of this component to the specified output stream.

Parameters:
out - a print stream.
 o list
 public void list(PrintStream out,
                  int indent)
Prints out a list, starting at the specified indention, to the specified print stream.

Parameters:
out - a print stream.
indent - number of spaces to indent.
See Also:
println
 o list
 public void list(PrintWriter out)
Prints a listing to the specified print writer.

Parameters:
out - The print writer to print to.
 o list
 public void list(PrintWriter out,
                  int indent)
Prints out a list, starting at the specified indention, to the specified print writer.

Parameters:
out - The print writer to print to.
indent - The number of spaces to indent.
See Also:
println

All Packages  Class Hierarchy  This Package  Previous  Next  Index

Submit a bug or feature - Version 1.1.8 of Java Platform API Specification
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1995-1999 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.