在特定的JTable单元格中显示图标

时间:2013-08-26 22:54:49

标签: java swing jtable icons

我想在特定的JTable单元格中显示图标,并且在整个列的单元格中没有相同的图标。

1 个答案:

答案 0 :(得分:1)

假设您已完成research并知道如何使用custom cell renderers,则基本概念很简单。

public Component getTableCellRendererComponent(
                        JTable table, Object color,
                        boolean isSelected, boolean hasFocus,
                        int row, int column) {
    // Prepare renderer as usual...

    // Check to see if the current row/column is within 
    // the acceptable range...
    // It would be usful if this information was coming from
    // some kind of model
    if (row == iconRow && column == iconColumn) {
        // Apply the icon for this cell renderer
    }
    return this;
}