java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JLabel
javax.swing.table.DefaultTableCellRenderer
- 所有已实现的接口:
-
ImageObserver
,MenuContainer
,Serializable
,Accessible
,SwingConstants
,TableCellRenderer
- 直接已知的子类:
-
DefaultTableCellRenderer.UIResource
用于在
JTable
中渲染(显示)单个单元格的标准类。
实现说明: 此类继承自JLabel
,一个标准组件类。但是JTable
使用一种独特的机制来渲染其单元格,因此需要对其单元格渲染器进行一些稍微修改的行为。表类定义了一个单元格渲染器,并将其用作在表中渲染所有单元格的橡皮图章;它渲染第一个单元格,更改该单元格渲染器的内容,将原点移动到新位置,重新绘制它,依此类推。标准的JLabel
组件并不是设计用于这种方式的使用,我们希望避免每次绘制单元格时触发revalidate
。这将大大降低性能,因为revalidate
消息将被传递到容器的层次结构,以确定是否会影响任何其他组件。由于渲染器仅在绘制操作的生命周期内作为父级,因此我们同样希望避免与绘制操作相关的遍历层次结构的开销。因此,此类覆盖了validate
、invalidate
、revalidate
、repaint
和firePropertyChange
方法,使其成为无操作,并仅覆盖isOpaque
方法以提高性能。如果您编写自己的渲染器,请牢记这种性能考虑。
警告: 此类的序列化对象将不兼容未来的Swing版本。当前的序列化支持适用于短期存储或在运行相同Swing版本的应用程序之间的RMI。从1.4开始,已将所有JavaBeans的长期存储支持添加到java.beans
包中。请参阅XMLEncoder
。
- 参见:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
DefaultTableCellRenderer
的一个子类,实现了UIResource
。Nested classes/interfaces declared in class javax.swing.JLabel
JLabel.AccessibleJLabel
Nested classes/interfaces declared in class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces declared in class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces declared in class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
Fields declared in class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Fields declared in class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields declared in interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Fields declared in 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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
firePropertyChange
(String propertyName, boolean oldValue, boolean newValue) 为了性能原因而重写。protected void
firePropertyChange
(String propertyName, Object oldValue, Object newValue) 为了性能原因而重写。getTableCellRendererComponent
(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) 返回默认的表格单元格渲染器。void
为了性能原因而重写。boolean
isOpaque()
为了性能原因而重写。void
repaint()
为了性能原因而重写。void
repaint
(long tm, int x, int y, int width, int height) 为了性能原因而重写。void
为了性能原因而重写。void
为了性能原因而重写。void
覆盖JComponent.setBackground
以将未选中背景颜色分配给指定的颜色。void
覆盖JComponent.setForeground
以将未选中前景颜色分配给指定的颜色。protected void
将要渲染的单元格的String
对象设置为value
。void
updateUI()
来自UIManager
的通知,外观和感觉[L&F]已更改。void
validate()
为了性能原因而重写。Methods declared in 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
Methods declared in class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, 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 declared in 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 declared in 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, 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
-
Field Details
-
noFocusBorder
一个没有焦点的边框。
-
-
Constructor Details
-
DefaultTableCellRenderer
public DefaultTableCellRenderer()创建一个默认的表格单元格渲染器。
-
-
Method Details
-
setForeground
覆盖JComponent.setForeground
以将未选中前景颜色分配给指定的颜色。- 覆盖:
-
setForeground
在类JComponent
中 - 参数:
-
c
- 将前景颜色设置为此值 - 参见:
-
setBackground
覆盖JComponent.setBackground
以将未选中背景颜色分配给指定的颜色。- 覆盖:
-
setBackground
在类JComponent
中 - 参数:
-
c
- 将背景颜色设置为此值 - 参见:
-
updateUI
public void updateUI()来自UIManager
的通知,外观和感觉[L&F]已更改。用最新版本从UIManager
替换当前UI对象。 -
getTableCellRendererComponent
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) 返回默认的表格单元格渲染器。在打印操作期间,将使用
isSelected
和hasFocus
值为false
调用此方法,以防止选择和焦点出现在打印输出中。要根据表格是否正在打印来进行其他自定义,请检查从JComponent.isPaintingForPrint()
返回的返回值。- 指定者:
-
getTableCellRendererComponent
在接口TableCellRenderer
中 - 参数:
-
table
-JTable
-
value
- 要分配给[row, column]
处单元格的值 -
isSelected
- 如果单元格已选中,则为true -
hasFocus
- 如果单元格具有焦点,则为true -
row
- 要渲染的单元格的行 -
column
- 要渲染的单元格的列 - 返回:
- 默认的表格单元格渲染器
- 参见:
-
isOpaque
public boolean isOpaque()为了性能原因而重写。更多信息请参见实现说明。- 覆盖:
-
isOpaque
在类JComponent
中 - 返回:
- 如果此组件完全不透明,则为true
- 参见:
-
invalidate
public void invalidate()为了性能原因而重写。更多信息请参见实现说明。- 覆盖:
-
invalidate
在类Container
中 - 自:
- 1.5
- 参见:
-
validate
public void validate()为了性能原因而重写。更多信息请参见实现说明。 -
revalidate
public void revalidate()为了性能原因而重写。更多信息请参见实现说明。- 覆盖:
-
revalidate
在类JComponent
中 - 参见:
-
repaint
public void repaint(long tm, int x, int y, int width, int height) 为了性能原因而重写。有关更多信息,请参见实现说明。- 覆盖:
-
repaint
在类中JComponent
- 参数:
-
tm
- 此参数未被使用 -
x
- 脏区域的x值 -
y
- 脏区域的y值 -
width
- 脏区域的宽度 -
height
- 脏区域的高度 - 另请参见:
-
repaint
为了性能原因而重写。有关更多信息,请参见实现说明。- 覆盖:
-
repaint
在类中JComponent
- 参数:
-
r
- 包含脏区域的Rectangle
- 另请参见:
-
repaint
public void repaint()为了性能原因而重写。有关更多信息,请参见实现说明。 -
firePropertyChange
为了性能原因而重写。有关更多信息,请参见实现说明。- 覆盖:
-
firePropertyChange
在类中Component
- 参数:
-
propertyName
- 值已更改的属性 -
oldValue
- 属性的先前值 -
newValue
- 属性的新值
-
firePropertyChange
为了性能原因而重写。有关更多信息,请参见实现说明。- 覆盖:
-
firePropertyChange
在类中JComponent
- 参数:
-
propertyName
- 值已更改的属性 -
oldValue
- 属性的先前值 -
newValue
- 属性的新值
-
setValue
设置正在呈现的单元格的String
对象为value
。- 参数:
-
value
- 此单元格的字符串值;如果值为null
,则将文本值设置为空字符串 - 另请参见:
-