Need help on JTable, and change cell color...
Hi,
I got this Method from Internet to change the cell color in JTable,
the code changes the whole column color .
my question is : how to change the cell color if it has a negative value and leave black if it's positive.
here the Method I copied from Internet...
public static void setCellRenderer(JTable CustDtlsTbl) {
TableCellRenderer cellRenderer = createCellRenderer();
CustDtlsTbl.setDefaultRenderer(Object.class, cellRenderer);
}
public static TableCellRenderer createCellRenderer() {
return new DefaultTableCellRenderer() {
@Override
public Component getTableCellRendererComponent(JTable CustDtlsTbl, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Component cell = super.getTableCellRendererComponent(CustDtlsTbl, value, isSelected, hasFocus, row, column);
cell.setForeground(Color.RED);
return cell;
}
};
Thanks
|