我想同时为特定的单元格着色jtable
例如,具有column = 1
和row i+2
(i from 0 to 5 ) 的单元格。
CustomTableCellRenderer
我使用示例显示成功地为特定单元格着色
public class CustomTableCellRenderer extends DefaultTableCellRenderer
{
int x;
int y;
CustomTableCellRenderer(int x,int y){ //constructor
this.x= x;
this.y=y;
}
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,boolean hasFocus, int row, int column)
{
Component cell = super.getTableCellRendererComponent
(table, value, isSelected, hasFocus, row, column);
if ( ((row == x) && (column == y))) { //test of equivalence of x and y as parameter
cell.setBackground(Color.green);
}
else {
cell.setBackground(Color.WHITE);
}
return cell;
}
}