1 42 43 package org.jfree.ui; 44 45 import java.awt.Component ; 46 import java.text.DateFormat ; 47 48 import javax.swing.JTable ; 49 import javax.swing.SwingConstants ; 50 import javax.swing.table.DefaultTableCellRenderer ; 51 52 57 public class DateCellRenderer extends DefaultTableCellRenderer { 58 59 60 private DateFormat formatter; 61 62 65 public DateCellRenderer() { 66 this(DateFormat.getDateTimeInstance()); 67 } 68 69 74 public DateCellRenderer(final DateFormat formatter) { 75 super(); 76 this.formatter = formatter; 77 setHorizontalAlignment(SwingConstants.CENTER); 78 } 79 80 94 public Component getTableCellRendererComponent(final JTable table, 95 final Object value, final boolean isSelected, 96 final boolean hasFocus, final int row, final int column) { 97 98 setFont(null); 99 if (value != null) { 100 setText(this.formatter.format(value)); 101 } 102 else { 103 setText(""); 104 } 105 if (isSelected) { 106 setBackground(table.getSelectionBackground()); 107 } 108 else { 109 setBackground(null); 110 } 111 return this; 112 } 113 114 } 115 | Popular Tags |