|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JLabel
javax.swing.table.DefaultTableCellRenderer
public class DefaultTableCellRenderer
呈现(显示) JTable 中每个单元格的标准类。
实现注意事项:此类继承自一个标准的组件类 JLabel。但是 JTable 为其单元格的呈现使用了特殊的机制,因此要求稍微对其单元格渲染器的行为进行修改。该 table 类定义一个单元格渲染器,并将其用作呈现表中所有单元格的橡皮图章;它呈现第一个单元格、更改该单元格渲染器的内容、将原点移到新的位置、重新进行绘制,等等。标准的 JLabel 组件不是通过此方式使用的,每次绘制单元格时,我们都希望避免触发 revalidate 事件。这会大大降低程序的性能,因为 revalidate 消息会沿容器的层次结构向上传递,以确定任意其他组件是否将受到影响。由于该渲染器是绘制操作生命周期中唯一的父类,类似地,我们也希望避免与为进行绘制操作而遍历容器层次结构相关联的开销。所以此类将 validate、invalidate、revalidate、repaint 和 firePropertyChange 方法重写为无操作,并单独重写 isOpaque 方法以提高性能。如果您编写自己的渲染器,请记住此性能方面的考虑。
警告:此类的已序列化对象与以后的 Swing 版本不兼容。当前的序列化支持适用于短期存储或运行相同 Swing 版本的应用程序之间的 RMI。从 1.4 版本开始,已在 java.beans 包中添加了支持所有 JavaBeansTM 长期存储的功能。请参见 XMLEncoder。
JTable
| 嵌套类摘要 | |
|---|---|
static class |
DefaultTableCellRenderer.UIResource DefaultTableCellRenderer 的一个子类,它实现 UIResource。 |
| 从类 javax.swing.JLabel 继承的嵌套类/接口 |
|---|
JLabel.AccessibleJLabel |
| 从类 javax.swing.JComponent 继承的嵌套类/接口 |
|---|
JComponent.AccessibleJComponent |
| 从类 java.awt.Container 继承的嵌套类/接口 |
|---|
Container.AccessibleAWTContainer |
| 从类 java.awt.Component 继承的嵌套类/接口 |
|---|
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy |
| 字段摘要 | |
|---|---|
protected static Border |
noFocusBorder 一个空 Border。 |
| 从类 javax.swing.JLabel 继承的字段 |
|---|
labelFor |
| 从类 javax.swing.JComponent 继承的字段 |
|---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
| 从类 java.awt.Component 继承的字段 |
|---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| 从接口 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 |
| 从接口 java.awt.image.ImageObserver 继承的字段 |
|---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| 构造方法摘要 | |
|---|---|
DefaultTableCellRenderer() 创建一个默认的表单元格渲染器。 |
|
| 方法摘要 | |
|---|---|
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() 因为性能原因而被重写。 |
| 从类 java.lang.Object 继承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| 字段详细信息 |
|---|
protected static Border noFocusBorder
Border。可以不使用此字段。要更改此渲染器所使用的
Border,请重写
getTableCellRendererComponent 方法并直接设置所返回组件的边界。
| 构造方法详细信息 |
|---|
public DefaultTableCellRenderer()
| 方法详细信息 |
|---|
public void setForeground(Color c)
JComponent.setForeground 将未选定单元格的前景色分配为指定颜色。
JComponent 中的
setForeground
c - 将前景色设置为此值
Component.getForeground()
public void setBackground(Color c)
JComponent.setBackground 将未选定单元格的背景色分配为指定颜色。
JComponent 中的
setBackground
c - 将背景色设置为此值
Component.getBackground(),
JComponent.setOpaque(boolean)
public void updateUI()
UIManager 的关于外观 [L&F] 已更改的通知。用取自
UIManager 的最新版本 UI 对象替换当前的 UI 对象。
JLabel 中的
updateUI
JComponent.updateUI()
public Component getTableCellRendererComponent(JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column)
在打印操作期间,将调用此方法(isSelected 和 hasFocus 为 false)阻止选择和焦点在打印输出中出现。要根据是否打印表进行其他定制,检查 JComponent.isPaintingForPrint() 的返回值。
TableCellRenderer 中的
getTableCellRendererComponent
table -
JTable
value - 分配给
[row, column] 处单元格的值
isSelected - 如果已选定单元格,则为 true
hasFocus - 如果单元格具有焦点,则为 true
row - 要呈现的单元格所在行
column - 要呈现的单元格所在列
JComponent.isPaintingForPrint()
public boolean isOpaque()
JComponent 中的
isOpaque
JComponent.setOpaque(boolean)
public void invalidate()
Container 中的
invalidate
Container.validate(),
Container.layout(),
LayoutManager,
LayoutManager2.invalidateLayout(Container)
public void validate()
Container 中的
validate
Container.add(java.awt.Component),
Component.invalidate(),
JComponent.revalidate(),
Container.validateTree()
public void revalidate()
JComponent 中的
revalidate
Component.invalidate(),
Container.validate(),
JComponent.isValidateRoot(),
RepaintManager.addInvalidComponent(javax.swing.JComponent)
public void repaint(long tm,
int x,
int y,
int width,
int height)
JComponent 中的
repaint
tm - 不使用此参数
x - 脏区的 x 值
y - 脏区的 y 值
width - 脏区的宽度
height - 脏区的高度
Component.isShowing(),
RepaintManager.addDirtyRegion(javax.swing.JComponent, int, int, int, int)
public void repaint(Rectangle r)
JComponent 中的
repaint
r - 包含脏区的
Rectangle
Component.isShowing(),
RepaintManager.addDirtyRegion(javax.swing.JComponent, int, int, int, int)
public void repaint()
Component 中的
repaint
Component.update(Graphics)
protected void firePropertyChange(String propertyName,
Object oldValue,
Object newValue)
Component 中的
firePropertyChange
propertyName - 其值已改变的属性
oldValue - 该属性以前的值
newValue - 该属性的新值
public void firePropertyChange(String propertyName,
boolean oldValue,
boolean newValue)
JComponent 中的
firePropertyChange
propertyName - 其值已更改的属性
oldValue - 该属性以前的值
newValue - 该属性的新值
protected void setValue(Object value)
String 对象设置为
value。
value - 此单元格的字符串值;如果 value 为
null,则将文本值设置为空字符串
JLabel.setText(java.lang.String)
|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。