private class TableCellRenderer extends DefaultTableCellRenderer {
@Override
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus, int row,
int column) {
super.getTableCellRendererComponent(table, value, isSelected,
hasFocus, row, column);
setForeground(Color.RED);
return this;
}
@Override
protected void paintComponent(Graphics g) {
Color orig = g.getColor();
int h = (int)getHeight() / 2;
g.setColor(Color.BLUE);
g.fillRect(0, 0, getWidth(), h);
g.setColor(Color.GREEN);
g.fillRect(0, h + 1, getWidth(), h - 1);
g.setColor(orig);
super.paintComponent(g);
}
}
table.getColumnModel().getColumn(0).setCellRenderer(new TableCellRenderer());
if(row==0){
super....
}
private class SpecialTableCellRenderer extends DefaultTableCellRenderer {
int rows = 0;
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean
hasFocus, int row, int column) {
this.rows = row;
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
setForeground(Color.RED);
return this;
}
protected void paintComponent(Graphics g) {
if (rows == 0) {
Color orig = g.getColor();
int h = (int) getHeight() / 2;
g.setColor(Color.BLUE);
g.fillRect(0, 0, getWidth(), h);
g.setColor(Color.GREEN);
g.fillRect(0, h + 1, getWidth(), h - 1);
g.setColor(orig);
}
super.paintComponent(g);
}
}
Grüße Oli