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
| Modifier and Type | Class and Description |
|---|---|
static class |
DefaultTableCellRenderer.UIResource
DefaultTableCellRenderer的子类实现
UIResource 。
|
JLabel.AccessibleJLabelJComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy| Modifier and Type | Field and Description |
|---|---|
protected static Border |
noFocusBorder
|
listenerList,
TOOL_TIP_TEXT_KEY,
ui, UNDEFINED_CONDITION,
WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,
WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
accessibleContext,
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT,
LEFT_ALIGNMENT, RIGHT_ALIGNMENT,
TOP_ALIGNMENT
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WESTABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH| Constructor and Description |
|---|
DefaultTableCellRenderer()
创建一个默认的表单元格渲染器。
|
| Modifier and Type | Method and Description |
|---|---|
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()
由于性能原因而被覆盖。
|
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
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
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
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, getPeer, 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, resize,
resize, setBounds,
setBounds,
setComponentOrientation,
setCursor,
setDropTarget,
setFocusable,
setFocusTraversalKeysEnabled,
setIgnoreRepaint,
setLocale,
setLocation, setLocation,
setName, setSize,
setSize, show, show, size, toString, transferFocus,
transferFocusBackward,
transferFocusUpCycle
protected static Border noFocusBorder
public void setForeground(Color c)
JComponent.setForeground以将未选择的前景颜色分配给指定的颜色。
setForeground在
JComponent
c - 将
c设置为此值
Component.getForeground()
public void setBackground(Color c)
JComponent.setBackground以将未选择的背景颜色分配给指定的颜色。
setBackground在
JComponent
c - 将背景颜色设置为此值
Component.getBackground()
,
JComponent.setOpaque(boolean)
public void updateUI()
UIManager的外观和感觉[L&F]已经改变。
从UIManager替换最新版本的当前UI对象。
updateUI在
JLabel类
JComponent.updateUI()
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 - 要呈现的单元格的列
JComponent.isPaintingForPrint()
public boolean isOpaque()
isOpaque在
JComponent
JComponent.setOpaque(boolean)
public void invalidate()
invalidate在
Container
Container.validate() , Container.layout() , LayoutManager2
public void validate()
public void revalidate()
public void repaint(long tm,
int x,
int y,
int width,
int height)
repaint在
JComponent
tm - 不使用此参数
x - 脏区域的x值
y - 脏区域的y值
width - 脏区域的宽度
height - 脏区域的高度
JComponent.isPaintingOrigin()
,
Component.isShowing()
,
RepaintManager.addDirtyRegion(javax.swing.JComponent,
int, int, int, int)
public void repaint(Rectangle r)
repaint在
JComponent
r - 一个
Rectangle脏区域的
Rectangle
JComponent.isPaintingOrigin()
,
Component.isShowing()
,
RepaintManager.addDirtyRegion(javax.swing.JComponent,
int, int, int, int)
public void repaint()
repaint在
Component
Component.update(Graphics)
protected void firePropertyChange(String propertyName, Object oldValue, Object newValue)
firePropertyChange在
Component类
propertyName - 其值已更改的属性
oldValue - 该物业的以前的价值
newValue - 该物业的新价值
public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue)
firePropertyChange在
JComponent
propertyName - 其值已更改的属性
oldValue - 该物业的以前的价值
newValue - 房产的新值
protected void setValue(Object value)
String对象设置为
value 。
value - 此单元格的字符串值;
如果值为null ,则将文本值设置为空字符串
JLabel.setText(java.lang.String)