当我在jtable单元格中添加JDAteChooser时,它工作得非常好但是当我开始使用jDatechooser添加日期时,他将这种格式的日期设置为“2016-12-31 Sun Dec 18 11:33:56 WAT 2016”,我想要它的格式为YYYY-MM-dd 这是我的JDateChooserCellEditor。
package Acteur;
import com.toedter.calendar.JDateChooser;
import java.awt.Component;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.AbstractCellEditor;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.event.CellEditorListener;
import javax.swing.event.ChangeEvent;
import javax.swing.plaf.basic.BasicTreeUI;
import javax.swing.table.TableCellEditor;
/**
* A CellEditor for tables, using a JDateChooser.
*
* @author Kai Toedter
* @version $LastChangedRevision: 100 $
* @version $LastChangedDate: 2006-06-04 14:36:06 +0200 (So, 04 Jun 2006) $
*/
public class JDateChooserCellEditor extends AbstractCellEditor implements
TableCellEditor {
private static final long serialVersionUID = 917881575221755609L;
private JDateChooser dateChooser = new JDateChooser();
public Component getTableCellEditorComponent(JTable table, Object value,
boolean isSelected, int row, int column) {
System.out.println("HICEM"+this.getCellEditorValue());
return dateChooser;
}
@Override
public Date getCellEditorValue() {
return dateChooser.getDate();
}
}
我在这里称呼它:
public AlerteCarte() {
initComponents();
DefaultTableModel model = (DefaultTableModel) Table.getTable().getModel();
this.jTable1.setModel(model);
TableColumn column1 = jTable1.getColumnModel().getColumn(3);
//column1.setCellRenderer( new JDateChooserRenderer());
column1.setCellEditor(new JDateChooserCellEditor());
TableColumn column2 = jTable1.getColumnModel().getColumn(2);
//column2.setCellRenderer( new JDateChooserRenderer());
column2.setCellEditor(new JDateChooserCellEditor());
jTable1.setRowHeight(30);
jTable1.getColumnModel().getColumn(2).setPreferredWidth(100);
jTable1.getColumnModel().getColumn(3).setPreferredWidth(100);
}