Paints a component to the specified
Graphics
.
This method is primarily useful to render
Component
s that don't exist as part of the visible
containment hierarchy, but are used for rendering. For
example, if you are doing your own rendering and want to render
some text (or even HTML), you could make use of
JLabel
's text rendering support and have it paint
directly by way of this method, without adding the label to the
visible containment hierarchy.
This method makes use of CellRendererPane
to handle
the actual painting, and is only recommended if you use one
component for rendering. If you make use of multiple components
to handle the rendering, as JTable
does, use
CellRendererPane
directly. Otherwise, as described
below, you could end up with a CellRendererPane
per Component
.
If c
's parent is not a CellRendererPane
,
a new CellRendererPane
is created, c
is
added to it, and the CellRendererPane
is added to
p
. If c
's parent is a
CellRendererPane
and the CellRendererPane
s
parent is not p
, it is added to p
.
The component should either descend from JComponent
or be another kind of lightweight component.
A lightweight component is one whose "lightweight" property
(returned by the Component
isLightweight
method)
is true. If the Component is not lightweight, bad things map happen:
crashes, exceptions, painting problems...
Parameters:
- g - the Graphics
object to draw on
- c - the Component
to draw
- p - the intermediate Container
- x - an int specifying the left side of the area draw in, in pixels,
measured from the left edge of the graphics context
- y - an int specifying the top of the area to draw in, in pixels
measured down from the top edge of the graphics context
- w - an int specifying the width of the area draw in, in pixels
- h - an int specifying the height of the area draw in, in pixels
See Also:
CellRendererPane
,
Component.isLightweight()
,