我试图在JTable传递线参数和列以及所需的颜色颜色中定义单元格的颜色。然而,他实施的方式是描绘整个专栏的特定点。
...
table.getColumnModel().getColumn(2).
setCellRenderer(new CellRenderer(3,2,new Color(24,65,87)));
class CellRenderer extends DefaultTableCellRenderer {
private static final long serialVersionUID = 1L;
private Integer row;
private Integer col;
private Color color;
public CellRenderer(Integer row, Integer col, Color color) {
this.row = row;
this.col = col;
this.color = color;
}
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int col) {
Component c = super.getTableCellRendererComponent(table, value,
isSelected, hasFocus, row, col);
if(this.row == row && this.col == col){
c.setBackground(this.color);
}
return c;
}
}
答案 0 :(得分:0)
单元格渲染器用于给定列或对象类型的所有单元格。您需要提供一些维护您要使用的信息的对象,以便渲染器可以决定要突出显示的内容
或者使用具有突出显示功能的SwingLabs SwingX库中的JXTable