- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JLabel
-
- javax.swing.table.DefaultTableCellRenderer
-
- All Implemented Interfaces:
-
ImageObserver
,MenuContainer
,Serializable
,Accessible
,SwingConstants
,TableCellRenderer
public class DefaultTableCellRenderer extends JLabel implements TableCellRenderer, Serializable
在JTable
渲染(显示)单个单元格的标准类。Implementation Note:这个类继承自
JLabel
标准的组件类。 然而,JTable
采用独特的机制来渲染其单元格,因此需要从其单元格渲染器稍微修改一些行为。 表类定义单个单元格渲染器,并将其用作橡皮图章来呈现表中的所有单元格; 它渲染第一个单元格,更改该单元格渲染器的内容,将原始位置移动到新位置,重新绘制它等等。 标准的JLabel
组件并未设计为以这种方式使用,我们希望在每次绘制单元时避免触发revalidate
。 这将大大降低性能,因为revalidate
消息将被传递到容器的层次结构,以确定是否会影响任何其他组件。 由于渲染器在绘画操作的整个生命周期中才是父母,我们同样希望避免与绘制操作的层次结构相关的开销。 所以这个类覆盖了validate
,invalidate
,revalidate
,repaint
,并firePropertyChange
方法是无操作和覆盖isOpaque
方法只是为了提高性能。 如果你写自己的渲染器,请记住这个性能考虑。警告:此类的序列化对象与将来的Swing版本不兼容。 当前的序列化支持适用于运行相同版本的Swing的应用程序之间的短期存储或RMI。 从1.4开始,支持所有JavaBeans的长期存储已被添加到
java.beans
包中。 请参阅XMLEncoder
。- 另请参见:
-
JTable
, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class 描述 static class
DefaultTableCellRenderer.UIResource
DefaultTableCellRenderer
的子类实现UIResource
。-
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
-
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
-
Nested classes/interfaces inherited from class javax.swing.JLabel
JLabel.AccessibleJLabel
-
-
Field Summary
Fields Modifier and Type Field 描述 protected static Border
noFocusBorder
边框无焦点。-
Fields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
-
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
-
-
构造方法摘要
构造方法 Constructor 描述 DefaultTableCellRenderer()
创建一个默认的表单元格渲染器。
-
方法摘要
所有方法 接口方法 具体的方法 Modifier and Type 方法 描述 void
firePropertyChange(String propertyName, boolean oldValue, boolean newValue)
由于性能原因而被覆盖。protected void
firePropertyChange(String propertyName, Object oldValue, Object newValue)
由于性能原因而被覆盖。Component
getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
返回默认的表格单元格渲染器。void
invalidate()
由于性能原因而被覆盖。boolean
isOpaque()
由于性能原因而被覆盖。void
repaint()
由于性能原因而被覆盖。void
repaint(long tm, int x, int y, int width, int height)
由于性能原因而被覆盖。void
repaint(Rectangle r)
由于性能原因而被覆盖。void
revalidate()
由于性能原因而被覆盖。void
setBackground(Color c)
覆盖JComponent.setBackground
以将未选择的背景颜色分配给指定的颜色。void
setForeground(Color c)
覆盖JComponent.setForeground
以将未选择的前景颜色分配给指定的颜色。protected void
setValue(Object value)
将要呈现的单元格的String
对象设置为value
。void
updateUI()
通知从UIManager
的外观和感觉[L&F]已经改变。void
validate()
由于性能原因而被覆盖。-
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validateTree
-
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
-
Methods inherited from class javax.swing.JLabel
checkHorizontalKey, checkVerticalKey, getAccessibleContext, getDisabledIcon, getDisplayedMnemonic, getDisplayedMnemonicIndex, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getLabelFor, getText, getUI, getUIClassID, getVerticalAlignment, getVerticalTextPosition, imageUpdate, paramString, setDisabledIcon, setDisplayedMnemonic, setDisplayedMnemonic, setDisplayedMnemonicIndex, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabelFor, setText, setUI, setVerticalAlignment, setVerticalTextPosition
-
-
-
-
字段详细信息
-
noFocusBorder
protected static Border noFocusBorder
边框无焦点。
-
-
方法详细信息
-
setForeground
public void setForeground(Color c)
覆盖JComponent.setForeground
以将未选择的前景颜色分配给指定的颜色。- 重写:
-
setForeground
在JComponent
- 参数
-
c
- 将前景颜色设置为此值 - 另请参见:
-
Component.getForeground()
-
setBackground
public void setBackground(Color c)
覆盖JComponent.setBackground
以将未选择的背景颜色分配给指定的颜色。- 重写:
-
setBackground
在JComponent
- 参数
-
c
- 将背景颜色设置为此值 - 另请参见:
-
Component.getBackground()
,JComponent.setOpaque(boolean)
-
updateUI
public void updateUI()
通知从UIManager
的外观和感觉[L&F]已经改变。 用UIManager
替换最新版本的当前UI对象。- 重写:
-
updateUI
在JLabel
- 另请参见:
-
JComponent.updateUI()
-
getTableCellRendererComponent
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
返回默认的表格单元格渲染器。在打印操作期间,此方法将被调用
isSelected
个hasFocus
的值false
,以防止选择和从出现在打印输出聚焦。 要根据是否打印表进行其他自定义,请从JComponent.isPaintingForPrint()
检查返回值。- Specified by:
-
getTableCellRendererComponent
在接口TableCellRenderer
- 参数
-
table
-JTable
-
value
- 要分配给[row, column]
的单元格的[row, column]
-
isSelected
- 如果选择单元格,则为true -
hasFocus
- 如果单元格具有焦点,hasFocus
true -
row
- 要呈现的单元格行 -
column
- 要呈现的单元格的列 - 结果
- 默认表单元格渲染器
- 另请参见:
-
JComponent.isPaintingForPrint()
-
isOpaque
public boolean isOpaque()
由于性能原因而被覆盖。 有关详细信息,请参阅Implementation Note 。- 重写:
-
isOpaque
在JComponent
- 结果
- 如果此组件完全不透明,则为true
- 另请参见:
-
JComponent.setOpaque(boolean)
-
invalidate
public void invalidate()
由于性能原因而被覆盖。 有关详细信息,请参阅Implementation Note 。- 重写:
-
invalidate
在Container
- 从以下版本开始:
- 1.5
- 另请参见:
-
Container.validate()
,Container.layout()
,LayoutManager2
-
validate
public void validate()
由于性能原因而被覆盖。 有关详细信息,请参阅Implementation Note 。
-
revalidate
public void revalidate()
由于性能原因而被覆盖。 有关详细信息,请参阅Implementation Note 。
-
repaint
public void repaint(long tm, int x, int y, int width, int height)
由于性能原因而被覆盖。 有关详细信息,请参阅Implementation Note 。- 重写:
-
repaint
在JComponent
- 参数
-
tm
- 不使用此参数 -
x
- 脏区域的x值 -
y
- 脏区域的y值 -
width
- 脏区域的宽度 -
height
- 脏区域的高度 - 另请参见:
-
JComponent.isPaintingOrigin()
,Component.isShowing()
,RepaintManager.addDirtyRegion(javax.swing.JComponent, int, int, int, int)
-
repaint
public void repaint(Rectangle r)
由于性能原因而被覆盖。 有关详细信息,请参阅Implementation Note 。- 重写:
-
repaint
在JComponent
- 参数
-
r
- 一个包含脏区域的Rectangle
- 另请参见:
-
JComponent.isPaintingOrigin()
,Component.isShowing()
,RepaintManager.addDirtyRegion(javax.swing.JComponent, int, int, int, int)
-
repaint
public void repaint()
由于性能原因而被覆盖。 有关详细信息,请参阅Implementation Note 。- 重写:
-
repaint
在Component
- 从以下版本开始:
- 1.5
- 另请参见:
-
Component.update(Graphics)
-
firePropertyChange
protected void firePropertyChange(String propertyName, Object oldValue, Object newValue)
由于性能原因而被覆盖。 有关详细信息,请参阅Implementation Note 。- 重写:
-
firePropertyChange
在Component
- 参数
-
propertyName
- 其值已更改的属性 -
oldValue
- 该物业的以前的价值 -
newValue
- 该物业的新价值
-
firePropertyChange
public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue)
由于性能原因而被覆盖。 有关详细信息,请参阅Implementation Note 。- 重写:
-
firePropertyChange
在JComponent
- 参数
-
propertyName
- 其值已更改的属性 -
oldValue
- 该物业的以前的价值 -
newValue
- 该物业的新值
-
setValue
protected void setValue(Object value)
将要呈现的单元格的String
对象设置为value
。- 参数
-
value
- 此单元格的字符串值; 如果值为null
,则将文本值设置为空字符串 - 另请参见:
-
JLabel.setText(java.lang.String)
-
-