JTable 从彼此相邻的相同值列中删除值

JTable remove value from same value columns next to each other

在 JTable 中,如何检测 DefaultTableCellRenderer 的 getTableCellRendererComponent 中一行中彼此相邻且具有相同值的所有单元格?然后我需要从除中心值以外的所有值中删除所述值。我试过

if(table.getValueAt(row, column-1) == value && table.getValueAt(row, column+1) == value) {
    setValue("K")
}

确保我至少可以检测到中心,但这只有在 3 个单元格具有相同值时才有效。我需要更多

if(table.getValueAt(row, column-1) == value && table.getValueAt(row, column+1) == value) {
    //add this
    for (int i = column; table.getValueAt(row, i) == value; i++)
        setValue("K");
}

您正在更改值并在之后进行比较,因此条件仅触发一次。

您可以遍历整行并检查每一行是否与您想要的值相同:

boolean same = true;
for (int col = 0; col < columnCount; col++) {
    if (table.getValueAt(row, col ) != value) {
         same = false;
         break;
    }
}
if (same) {
    setValue("K");
}