APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javax.swing

public Class CellRendererPane

extends Container
implements Accessible
Class Inheritance
All Implemented Interfaces
javax.accessibility.Accessible
Annotations
@SuppressWarnings:serial
Imports
java.awt.Color, .Component, .Container, .Graphics, .Rectangle, java.io.IOException, .ObjectOutputStream, .Serial, javax.accessibility.Accessible, .AccessibleContext, .AccessibleRole

This class is inserted in between cell renderers and the components that use them. It just exists to thwart the repaint() and invalidate() methods which would otherwise propagate up the tree when the renderer was configured. It's used by the implementations of JTable, JTree, and JList. For example, here's how CellRendererPane is used in the code the paints each row in a JList:
  cellRendererPane = new CellRendererPane();
  ...
  Component rendererComponent = renderer.getListCellRendererComponent();
  renderer.configureListCellRenderer(dataModel.getElementAt(row), row);
  cellRendererPane.paintComponent(g, rendererComponent, this, x, y, w, h);

A renderer component must override isShowing() and unconditionally return true to work correctly because the Swing paint does nothing for components with isShowing false.

Warning

Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeans has been added to the java.beans package. Please see java.beans.XMLEncoder.

Author
Hans Muller
Since
1.2

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected class
CellRendererPane.AccessibleCellRendererPane

This class implements accessibility support for the CellRendererPane class.

Field Summary

Modifier and TypeField and Description
protected AccessibleContext
accessibleContext

Hides java.awt.Component.accessibleContext.

AccessibleContext associated with this CellRendererPan

Constructor Summary

AccessConstructor and Description
public
CellRendererPane()

Construct a CellRendererPane object.

Method Summary

Modifier and TypeMethod and Description
protected void
addImpl(Component x, Object constraints, int index)

Overrides java.awt.Container.addImpl.

If the specified component is already a child of this then we don't bother doing anything - stacking order doesn't matter for cell renderer components (CellRendererPane doesn't paint anyway).

public AccessibleContext

Returns:

an AccessibleCellRendererPane that serves as the AccessibleContext of this CellRendererPane
getAccessibleContext
()

Overrides java.awt.Component.getAccessibleContext.

Implements javax.accessibility.Accessible.getAccessibleContext.

Gets the AccessibleContext associated with this CellRendererPane.

public void
invalidate()

Overrides java.awt.Container.invalidate.

Overridden to avoid propagating a invalidate up the tree when the cell renderer child is configured.

public void
paint(Graphics g)

Overrides java.awt.Container.paint.

Shouldn't be called.

public void
paintComponent(Graphics
the Graphics object to draw on
g
,
Component
the Component to draw
c
,
Container
the Container component actually drawn on
p
,
int
an int specifying the left side of the area draw in, in pixels, measured from the left edge of the graphics context
x
,
int
an int specifying the top of the area to draw in, in pixels measured down from the top edge of the graphics context
y
,
int
an int specifying the width of the area draw in, in pixels
w
,
int
an int specifying the height of the area draw in, in pixels
h
,
boolean
if true, component c will be validated before being painted
shouldValidate
)

Paint a cell renderer component c on graphics object g.

public void
paintComponent(Graphics
the Graphics object to draw on
g
,
Component
the Component to draw
c
,
Container
the Container component actually drawn on
p
,
int
an int specifying the left side of the area draw in, in pixels, measured from the left edge of the graphics context
x
,
int
an int specifying the top of the area to draw in, in pixels measured down from the top edge of the graphics context
y
,
int
an int specifying the width of the area draw in, in pixels
w
,
int
an int specifying the height of the area draw in, in pixels
h
)

Calls this.paintComponent(g, c, p, x, y, w, h, false).

public void
paintComponent(Graphics
the Graphics object to draw on
g
,
Component
the Component to draw
c
,
Container
the Container component actually drawn on
p
,
Rectangle
the Rectangle to draw in
r
)

Calls this.paintComponent(g, c, p, r.x, r.y, r.width, r.height) where r is the input Rectangle parameter.

public void
update(Graphics g)

Overrides java.awt.Container.update.

Shouldn't be called.

private void
writeObject(ObjectOutputStream s)

Hides java.awt.Container.writeObject.

Serializes this Container to the specified ObjectOutputStream.

Inherited from java.awt.Container:
addaddaddaddaddaddContainerListeneraddNotifyaddPropertyChangeListeneraddPropertyChangeListenerapplyComponentOrientationareFocusTraversalKeysSetcountComponentsdeliverEventdoLayoutfindComponentAtfindComponentAtgetAlignmentXgetAlignmentYgetComponentgetComponentAtgetComponentAtgetComponentCountgetComponentsgetComponentZOrdergetContainerListenersgetFocusTraversalKeysgetFocusTraversalPolicygetInsetsgetLayoutgetListenersgetMaximumSizegetMinimumSizegetMousePositiongetPreferredSizeinsetsisAncestorOfisFocusCycleRootisFocusCycleRootisFocusTraversalPolicyProviderisFocusTraversalPolicySetisValidateRootlayoutlistlistlocateminimumSizepaintComponentsparamStringpreferredSizeprintprintComponentsprocessContainerEventprocessEventremoveremoveremoveAllremoveContainerListenerremoveNotifysetComponentZOrdersetFocusCycleRootsetFocusTraversalKeyssetFocusTraversalPolicysetFocusTraversalPolicyProvidersetFontsetLayouttransferFocusDownCyclevalidatevalidateTree

Field Detail

accessibleContextback to summary
protected AccessibleContext accessibleContext

Hides java.awt.Component.accessibleContext.

AccessibleContext associated with this CellRendererPan

Constructor Detail

CellRendererPaneback to summary
public CellRendererPane()

Construct a CellRendererPane object.

Method Detail

addImplback to summary
protected void addImpl(Component x, Object constraints, int index)

Overrides java.awt.Container.addImpl.

If the specified component is already a child of this then we don't bother doing anything - stacking order doesn't matter for cell renderer components (CellRendererPane doesn't paint anyway).

getAccessibleContextback to summary
public AccessibleContext getAccessibleContext()

Overrides java.awt.Component.getAccessibleContext.

Implements javax.accessibility.Accessible.getAccessibleContext.

Gets the AccessibleContext associated with this CellRendererPane. For CellRendererPanes, the AccessibleContext takes the form of an AccessibleCellRendererPane. A new AccessibleCellRendererPane instance is created if necessary.

Returns:AccessibleContext

an AccessibleCellRendererPane that serves as the AccessibleContext of this CellRendererPane

invalidateback to summary
public void invalidate()

Overrides java.awt.Container.invalidate.

Overridden to avoid propagating a invalidate up the tree when the cell renderer child is configured.

paintback to summary
public void paint(Graphics g)

Overrides java.awt.Container.paint.

Shouldn't be called.

paintComponentback to summary
public void paintComponent(Graphics g, Component c, Container p, int x, int y, int w, int h, boolean shouldValidate)

Paint a cell renderer component c on graphics object g. Before the component is drawn it's reparented to this (if that's necessary), it's bounds are set to w,h and the graphics object is (effectively) translated to x,y. If it's a JComponent, double buffering is temporarily turned off. After the component is painted it's bounds are reset to -w, -h, 0, 0 so that, if it's the last renderer component painted, it will not start consuming input. The Container p is the component we're actually drawing on, typically it's equal to this.getParent(). If shouldValidate is true the component c will be validated before painted.

Parameters
g:Graphics

the Graphics object to draw on

c:Component

the Component to draw

p:Container

the Container component actually drawn on

x:int

an int specifying the left side of the area draw in, in pixels, measured from the left edge of the graphics context

y:int

an int specifying the top of the area to draw in, in pixels measured down from the top edge of the graphics context

w:int

an int specifying the width of the area draw in, in pixels

h:int

an int specifying the height of the area draw in, in pixels

shouldValidate:boolean

if true, component c will be validated before being painted

paintComponentback to summary
public void paintComponent(Graphics g, Component c, Container p, int x, int y, int w, int h)

Calls this.paintComponent(g, c, p, x, y, w, h, false).

Parameters
g:Graphics

the Graphics object to draw on

c:Component

the Component to draw

p:Container

the Container component actually drawn on

x:int

an int specifying the left side of the area draw in, in pixels, measured from the left edge of the graphics context

y:int

an int specifying the top of the area to draw in, in pixels measured down from the top edge of the graphics context

w:int

an int specifying the width of the area draw in, in pixels

h:int

an int specifying the height of the area draw in, in pixels

paintComponentback to summary
public void paintComponent(Graphics g, Component c, Container p, Rectangle r)

Calls this.paintComponent(g, c, p, r.x, r.y, r.width, r.height) where r is the input Rectangle parameter.

Parameters
g:Graphics

the Graphics object to draw on

c:Component

the Component to draw

p:Container

the Container component actually drawn on

r:Rectangle

the Rectangle to draw in

updateback to summary
public void update(Graphics g)

Overrides java.awt.Container.update.

Shouldn't be called.

writeObjectback to summary
private void writeObject(ObjectOutputStream s) throws IOException

Hides java.awt.Container.writeObject.

Doc from java.awt.Container.writeObject.

Serializes this Container to the specified ObjectOutputStream.

  • Writes default serializable fields to the stream.
  • Writes a list of serializable ContainerListener(s) as optional data. The non-serializable ContainerListener(s) are detected and no attempt is made to serialize them.
  • Write this Container's FocusTraversalPolicy if and only if it is Serializable; otherwise, null is written.
Annotations
@Serial
Exceptions
IOException:
if an I/O error occurs
javax.swing back to summary

protected Class CellRendererPane.AccessibleCellRendererPane

extends AccessibleAWTContainer
Class Inheritance

This class implements accessibility support for the CellRendererPane class.

Field Summary

Inherited from java.awt.Container.AccessibleAWTContainer:
accessibleContainerHandler

Constructor Summary

AccessConstructor and Description
protected
AccessibleCellRendererPane()

Constructs an AccessibleCellRendererPane.

Method Summary

Modifier and TypeMethod and Description
public AccessibleRole

Returns:

an instance of AccessibleRole describing the role of the object
getAccessibleRole
()

Overrides java.awt.Component.AccessibleAWTComponent.getAccessibleRole.

Get the role of this object.

Inherited from java.awt.Container.AccessibleAWTContainer:
addPropertyChangeListenergetAccessibleAtgetAccessibleChildgetAccessibleChildrenCountremovePropertyChangeListener

Constructor Detail

AccessibleCellRendererPaneback to summary
protected AccessibleCellRendererPane()

Constructs an AccessibleCellRendererPane.

Method Detail

getAccessibleRoleback to summary
public AccessibleRole getAccessibleRole()

Overrides java.awt.Component.AccessibleAWTComponent.getAccessibleRole.

Get the role of this object.

Returns:AccessibleRole

an instance of AccessibleRole describing the role of the object

See Also
AccessibleRole