【问题标题】:Display an icon in a specific JTable cell在特定的 JTable 单元格中显示图标
【发布时间】:2013-08-26 22:54:48
【问题描述】:

我想在特定的JTable 单元格中显示一个图标,而不是在整个列的单元格中显示相同的图标。

【问题讨论】:

  • 请编辑您的问题,在example 中添加一个sscce,显示您尝试过的内容。

标签: java swing jtable icons


【解决方案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;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-22
    • 2012-03-05
    • 2021-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-31
    相关资源
    最近更新 更多