JavaTM 2 Platform
Standard Ed. 6

javax.swing.table
接口 TableCellRenderer

所有已知实现类:
DefaultTableCellRenderer, DefaultTableCellRenderer.UIResource

public interface TableCellRenderer

此接口定义了要成为 JTable 中单元格渲染器的任意对象所需的方法。


方法摘要
 Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
          返回用于绘制单元格的组件。
 

方法详细信息

getTableCellRendererComponent

Component getTableCellRendererComponent(JTable table,
                                        Object value,
                                        boolean isSelected,
                                        boolean hasFocus,
                                        int row,
                                        int column)
返回用于绘制单元格的组件。此方法用于在绘制前适当地配置渲染器。

TableCellRenderer 还负责呈现表示该表当前 DnD 放置位置的单元格(如果有)。如果此呈现器负责呈现 DnD 放置位置,则它应该直接查询表以确定给定的行和列是否表示放置位置:

     JTable.DropLocation dropLocation = table.getDropLocation();
     if (dropLocation != null
             && !dropLocation.isInsertRow()
             && !dropLocation.isInsertColumn()
             && dropLocation.getRow() == row
             && dropLocation.getColumn() == column) {

         // this cell represents the current drop location
         // so render it specially, perhaps with a different color
     }
 

在打印操作期间,将调用此方法(isSelectedhasFocusfalse)阻止选择和焦点在打印输出中出现。要根据是否打印表进行其他定制,检查 JComponent.isPaintingForPrint() 的返回值。

参数:
table - 要求渲染器绘制的 JTable;可以为 null
value - 要呈现的单元格的值。由具体的渲染器解释和绘制该值。例如,如果 value 是字符串 "true",则它可呈现为字符串,或者也可呈现为已选中的复选框。null 是有效值
isSelected - 如果使用选中样式的高亮显示来呈现该单元格,则为 true;否则为 false
hasFocus - 如果为 true,则适当地呈现单元格。例如,在单元格上放入特殊的边框,如果可以编辑该单元格,则以彩色呈现它,用于指示正在进行编辑
row - 要绘制的单元格的行索引。绘制头时,row 值是 -1
column - 要绘制的单元格的列索引
另请参见:
JComponent.isPaintingForPrint()

JavaTM 2 Platform
Standard Ed. 6

提交错误或意见

版权所有 2008 Sun Microsystems, Inc. 保留所有权利。请遵守GNU General Public License, version 2 only