Top Description Inners Fields Constructors Methods
javax.swing.table

public Class DefaultTableCellRenderer

extends JLabel
implements TableCellRenderer, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, javax.swing.table.TableCellRenderer
Known Direct Subclasses
javax.swing.table.DefaultTableCellRenderer.UIResource, sun.swing.FilePane.DetailsTableCellRenderer, sun.swing.table.DefaultTableCellHeaderRenderer, javax.swing.plaf.synth.SynthTableUI.SynthTableCellRenderer
Annotations
@SuppressWarnings:serial
Imports
javax.swing.*, javax.swing.border.*, java.awt.Component, .Color, .Rectangle, java.io.Serializable, sun.swing.DefaultLookup, .SwingUtilities2

The standard class for rendering (displaying) individual cells in a JTable.

Implementation Note: This class inherits from JLabel, a standard component class. However JTable employs a unique mechanism for rendering its cells and therefore requires some slightly modified behavior from its cell renderer. The table class defines a single cell renderer and uses it as a as a rubber-stamp for rendering all cells in the table; it renders the first cell, changes the contents of that cell renderer, shifts the origin to the new location, re-draws it, and so on. The standard JLabel component was not designed to be used this way and we want to avoid triggering a revalidate each time the cell is drawn. This would greatly decrease performance because the revalidate message would be passed up the hierarchy of the container to determine whether any other components would be affected. As the renderer is only parented for the lifetime of a painting operation we similarly want to avoid the overhead associated with walking the hierarchy for painting operations. So this class overrides the validate, invalidate, revalidate, repaint, and firePropertyChange methods to be no-ops and override the isOpaque method solely to improve performance. If you write your own renderer, please keep this performance consideration in mind.

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
Philip Milne
See Also
JTable

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
DefaultTableCellRenderer.UIResource

A subclass of DefaultTableCellRenderer that implements UIResource.

Field Summary

Modifier and TypeField and Description
private static final Border
protected static Border
noFocusBorder

A border without focus.

private static final Border
SAFE_NO_FOCUS_BORDER

An empty Border.

private Color
private Color
Inherited from javax.swing.JLabel:
labelFor

Constructor Summary

AccessConstructor and Description
public
DefaultTableCellRenderer()

Creates a default table cell renderer.

Method Summary

Modifier and TypeMethod and Description
protected void
firePropertyChange(String
the property whose value has changed
propertyName
,
Object
the property's previous value
oldValue
,
Object
the property's new value
newValue
)

Overrides java.awt.Component.firePropertyChange.

Overridden for performance reasons.
public void
firePropertyChange(String
the property whose value has changed
propertyName
,
boolean
the property's previous value
oldValue
,
boolean
the property's new value
newValue
)

Overrides javax.swing.JComponent.firePropertyChange.

Overridden for performance reasons.
private Border
public Component

Returns:

the default table cell renderer
getTableCellRendererComponent
(JTable
the JTable
table
,
Object
the value to assign to the cell at [row, column]
value
,
boolean
true if cell is selected
isSelected
,
boolean
true if cell has focus
hasFocus
,
int
the row of the cell to render
row
,
int
the column of the cell to render
column
)

Implements javax.swing.table.TableCellRenderer.getTableCellRendererComponent.

Returns the default table cell renderer.
public void
invalidate()

Overrides java.awt.Container.invalidate.

Overridden for performance reasons.
public boolean
isOpaque()

Overrides javax.swing.JComponent.isOpaque.

Overridden for performance reasons.
public void
repaint(long
this parameter is not used
tm
,
int
the x value of the dirty region
x
,
int
the y value of the dirty region
y
,
int
the width of the dirty region
width
,
int
the height of the dirty region
height
)

Overrides javax.swing.JComponent.repaint.

Overridden for performance reasons.
public void
repaint(Rectangle
a Rectangle containing the dirty region
r
)

Overrides javax.swing.JComponent.repaint.

Overridden for performance reasons.
public void
repaint()

Overrides java.awt.Component.repaint.

Overridden for performance reasons.
public void
revalidate()

Overrides javax.swing.JComponent.revalidate.

Overridden for performance reasons.
public void
setBackground(Color
set the background color to this value
c
)

Overrides javax.swing.JComponent.setBackground.

Overrides JComponent.setBackground to assign the unselected-background color to the specified color.
public void
setForeground(Color
set the foreground color to this value
c
)

Overrides javax.swing.JComponent.setForeground.

Overrides JComponent.setForeground to assign the unselected-foreground color to the specified color.
protected void
setValue(Object
the string value for this cell; if value is null it sets the text value to an empty string
value
)

Sets the String object for the cell being rendered to value.

public void
updateUI()

Overrides javax.swing.JLabel.updateUI.

Notification from the UIManager that the look and feel [L&F] has changed.
public void
validate()

Overrides java.awt.Container.validate.

Overridden for performance reasons.
Inherited from javax.swing.JLabel:
checkHorizontalKeycheckVerticalKeygetAccessibleContextgetDisabledIcongetDisplayedMnemonicgetDisplayedMnemonicIndexgetHorizontalAlignmentgetHorizontalTextPositiongetIcongetIconTextGapgetLabelForgetTextgetUIgetUIClassIDgetVerticalAlignmentgetVerticalTextPositionimageUpdateparamStringsetDisabledIconsetDisplayedMnemonicsetDisplayedMnemonicsetDisplayedMnemonicIndexsetHorizontalAlignmentsetHorizontalTextPositionsetIconsetIconTextGapsetLabelForsetTextsetUIsetVerticalAlignmentsetVerticalTextPosition

Field Detail

DEFAULT_NO_FOCUS_BORDERback to summary
private static final Border DEFAULT_NO_FOCUS_BORDER
noFocusBorderback to summary
protected static Border noFocusBorder

A border without focus.

SAFE_NO_FOCUS_BORDERback to summary
private static final Border SAFE_NO_FOCUS_BORDER

An empty Border. This field might not be used. To change the Border used by this renderer override the getTableCellRendererComponent method and set the border of the returned component directly.

unselectedBackgroundback to summary
private Color unselectedBackground
unselectedForegroundback to summary
private Color unselectedForeground

Constructor Detail

DefaultTableCellRendererback to summary
public DefaultTableCellRenderer()

Creates a default table cell renderer.

Method Detail

firePropertyChangeback to summary
protected void firePropertyChange(String propertyName, Object oldValue, Object newValue)

Overrides java.awt.Component.firePropertyChange.

Overridden for performance reasons. See the Implementation Note for more information.

Parameters
propertyName:String

Doc from java.awt.Component.firePropertyChange.

the property whose value has changed

oldValue:Object

Doc from java.awt.Component.firePropertyChange.

the property's previous value

newValue:Object

Doc from java.awt.Component.firePropertyChange.

the property's new value

firePropertyChangeback to summary
public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue)

Overrides javax.swing.JComponent.firePropertyChange.

Overridden for performance reasons. See the Implementation Note for more information.

Parameters
propertyName:String

Doc from javax.swing.JComponent.firePropertyChange.

the property whose value has changed

oldValue:boolean

Doc from javax.swing.JComponent.firePropertyChange.

the property's previous value

newValue:boolean

Doc from javax.swing.JComponent.firePropertyChange.

the property's new value

getNoFocusBorderback to summary
private Border getNoFocusBorder()
Annotations
@SuppressWarnings:removal
getTableCellRendererComponentback to summary
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)

Implements javax.swing.table.TableCellRenderer.getTableCellRendererComponent.

Returns the default table cell renderer.

During a printing operation, this method will be called with isSelected and hasFocus values of false to prevent selection and focus from appearing in the printed output. To do other customization based on whether or not the table is being printed, check the return value from javax.swing.JComponent#isPaintingForPrint().

Parameters
table:JTable

the JTable

value:Object

the value to assign to the cell at [row, column]

isSelected:boolean

true if cell is selected

hasFocus:boolean

true if cell has focus

row:int

the row of the cell to render

column:int

the column of the cell to render

Returns:Component

the default table cell renderer

See Also
javax.swing.JComponent#isPaintingForPrint()
invalidateback to summary
public void invalidate()

Overrides java.awt.Container.invalidate.

Overridden for performance reasons. See the Implementation Note for more information.

Since
1.5
isOpaqueback to summary
public boolean isOpaque()

Overrides javax.swing.JComponent.isOpaque.

Overridden for performance reasons. See the Implementation Note for more information.

Returns:boolean

Doc from javax.swing.JComponent.isOpaque.

true if this component is completely opaque

repaintback to summary
public void repaint(long tm, int x, int y, int width, int height)

Overrides javax.swing.JComponent.repaint.

Overridden for performance reasons. See the Implementation Note for more information.

Parameters
tm:long

Doc from javax.swing.JComponent.repaint.

this parameter is not used

x:int

Doc from javax.swing.JComponent.repaint.

the x value of the dirty region

y:int

Doc from javax.swing.JComponent.repaint.

the y value of the dirty region

width:int

Doc from javax.swing.JComponent.repaint.

the width of the dirty region

height:int

Doc from javax.swing.JComponent.repaint.

the height of the dirty region

repaintback to summary
public void repaint(Rectangle r)

Overrides javax.swing.JComponent.repaint.

Overridden for performance reasons. See the Implementation Note for more information.

Parameters
r:Rectangle

Doc from javax.swing.JComponent.repaint.

a Rectangle containing the dirty region

repaintback to summary
public void repaint()

Overrides java.awt.Component.repaint.

Overridden for performance reasons. See the Implementation Note for more information.

Since
1.5
revalidateback to summary
public void revalidate()

Overrides javax.swing.JComponent.revalidate.

Overridden for performance reasons. See the Implementation Note for more information.

setBackgroundback to summary
public void setBackground(Color c)

Overrides javax.swing.JComponent.setBackground.

Overrides JComponent.setBackground to assign the unselected-background color to the specified color.

Parameters
c:Color

set the background color to this value

setForegroundback to summary
public void setForeground(Color c)

Overrides javax.swing.JComponent.setForeground.

Overrides JComponent.setForeground to assign the unselected-foreground color to the specified color.

Parameters
c:Color

set the foreground color to this value

setValueback to summary
protected void setValue(Object value)

Sets the String object for the cell being rendered to value.

Parameters
value:Object

the string value for this cell; if value is null it sets the text value to an empty string

See Also
JLabel#setText
updateUIback to summary
public void updateUI()

Overrides javax.swing.JLabel.updateUI.

Notification from the UIManager that the look and feel [L&F] has changed. Replaces the current UI object with the latest version from the UIManager.

See Also
JComponent#updateUI
validateback to summary
public void validate()

Overrides java.awt.Container.validate.

Overridden for performance reasons. See the Implementation Note for more information.

javax.swing.table back to summary

public Class DefaultTableCellRenderer.UIResource

extends DefaultTableCellRenderer
implements UIResource
Class Inheritance
All Implemented Interfaces
javax.swing.plaf.UIResource
Known Direct Subclasses
javax.swing.JTable.NumberRenderer, javax.swing.JTable.DateRenderer, javax.swing.JTable.IconRenderer
Annotations
@SuppressWarnings:serial

A subclass of DefaultTableCellRenderer that implements UIResource. DefaultTableCellRenderer doesn't implement UIResource directly so that applications can safely override the cellRenderer property with DefaultTableCellRenderer subclasses.

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.

Field Summary

Inherited from javax.swing.table.DefaultTableCellRenderer:
noFocusBorder

Constructor Summary

AccessConstructor and Description
public
UIResource()

Constructs a UIResource.

Method Summary

Inherited from javax.swing.table.DefaultTableCellRenderer:
firePropertyChangefirePropertyChangegetTableCellRendererComponentinvalidateisOpaquerepaintrepaintrepaintrevalidatesetBackgroundsetForegroundsetValueupdateUIvalidate

Constructor Detail

UIResourceback to summary
public UIResource()

Constructs a UIResource.