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

标签 java swing jtable icons

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

最佳答案

假设您已完成 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;
}

关于java - 在特定 JTable 单元格中显示图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18454343/

相关文章:

java - 使用 JNA 通过 Java 恢复对 Windows 目录的继承

java - 如何在已排序的jtable中的特定索引处插入空行?

java - 如何在JTable中设置标题

java - JTable只显示表格的右边框

java - DefaultTableModel 的 dataVector 的克隆问题

java - kubernetes pod 内存 - java gc 日志

java - 如何在互联网上使用 Eclipse 编写 Java 代码

java - 更改 JLabel 的文本 - 初学者

java - 我怎样才能让我的程序回复答案

Java swing 示例 - 满世界跑的 Ant 从堆里获取食物?