note as for all Renderers (excluding preparedRenderer)you have to/be sure that you have to call that after any column/row changes in JTable
TableColumnModel m = myTable.getColumnModel();
m.getColumn(5).setCellRenderer(new SubstDateRenderer());
here you can set BackGround, ForeGround for TableCell
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.table.DefaultTableCellRenderer;
public class SubstDateRenderer extends DefaultTableCellRenderer {
private static final long serialVersionUID = 1L;
private Date dateValue;
private SimpleDateFormat sdfNewValue = new SimpleDateFormat("dd.MMMM.yyyy");
private String sdfNewValueString = "";
public SubstDateRenderer() {// formating TableCell
super();
setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
}
@Override
public void setValue(Object value) {
if ((value != null) && (value instanceof Date)) {
dateValue = (Date) value;
sdfNewValueString = sdfNewValue.format(dateValue);
value = sdfNewValueString;
}
super.setValue(value);
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…