APIdia Launch Partner
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.IOException, .ObjectOutputStream, .Serial, .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
DEFAULT_NO_FOCUS_BORDER

An empty Border.

protected static Border
noFocusBorder

A border without focus.

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 propertyName, Object oldValue, Object newValue)

Overrides java.awt.Component.firePropertyChange.

Overridden for performance reasons.

public void
firePropertyChange(String propertyName, boolean oldValue, boolean 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 tm, int x, int y, int width, int height)

Overrides javax.swing.JComponent.repaint.

Overridden for performance reasons.

public void
repaint(Rectangle 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.

private void
writeObject(ObjectOutputStream s)

Hides javax.swing.JLabel.writeObject.

See readObject() and writeObject() in JComponent for more information about serialization in Swing.

Inherited from javax.swing.JLabel:
checkHorizontalKeycheckVerticalKeygetAccessibleContextgetDisabledIcongetDisplayedMnemonicgetDisplayedMnemonicIndexgetHorizontalAlignmentgetHorizontalTextPositiongetIcongetIconTextGapgetLabelForgetTextgetUIgetUIClassIDgetVerticalAlignmentgetVerticalTextPositionimageUpdateparamStringsetDisabledIconsetDisplayedMnemonicsetDisplayedMnemonicsetDisplayedMnemonicIndexsetHorizontalAlignmentsetHorizontalTextPositionsetIconsetIconTextGapsetLabelForsetTextsetUIsetVerticalAlignmentsetVerticalTextPosition

Field Detail

DEFAULT_NO_FOCUS_BORDERback to summary
private static final Border DEFAULT_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.

noFocusBorderback to summary
protected static Border noFocusBorder

A border without focus.

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.

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.

getNoFocusBorderback to summary
private Border getNoFocusBorder()
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.

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.

repaintback to summary
public void repaint(Rectangle r)

Overrides javax.swing.JComponent.repaint.

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

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.

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

Hides javax.swing.JLabel.writeObject.

See readObject() and writeObject() in JComponent for more information about serialization in Swing.

Annotations
@Serial
Exceptions
IOException:

Doc from java.awt.Container.writeObject.

if an I/O error occurs

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.