我的GUI中有一个JTable组件,它显示psuedocode了一个算法.我想通过更改特定单元格的背景然后更改下面的单元格等来突出显示当前的执行行.
现在我的代码改变了JTable中所有单元格的背景,如下图所示:

我用来存档这个当前状态的代码如下:
class CustomRenderer extends DefaultTableCellRenderer
{
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
{
JLabel d = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if((row == 0) && (column == 0))
d.setBackground(new java.awt.Color(255, 72, 72));
return d;
}
}
Run Code Online (Sandbox Code Playgroud)
然后我调用jTable2.setDefaultRenderer(String.class, new CustomRenderer());我的构造函数.
我认为:
如何修复我的代码,以便只有单元格(0,0)被着色?