0

我有一个包含字符串和日期数据类型列的 jtable。但是现在每个信息都以字符串数据的形式呈现,我想在 jtable 的日期列中呈现日期数据类型。

我还提供了以下数据模型的代码

public class MyTableModel extends AbstractTableModel {

    private List<List<Object>> dataList = new ArrayList<>();
     private String[] header = { "ID","SUBJECT","LETTTER FROM","LETTER DATE","DATE RECEIED",
                                  "REMARKS","DATE DISPATCHED","DESTINATION OFFICE"};



    public List<List<Object>> getDataList() {
        return dataList;
    }

    public void setDataList(List<List<Object>> dataList) {       
        this.dataList = dataList;
        fireTableDataChanged();       
        fireTableStructureChanged();        
    }

    public void setHeader(String[] header) {
        this.header = header;
    }

    public String[] getHeader() {
        return header;
    }

    @Override
    public int getRowCount() {
        return dataList.size();
    }

    @Override
    public int getColumnCount() {
        return header.length;
    }

    @Override
   public String getColumnName(int col) {
    return header[col];
   }

    @Override
    public Object getValueAt(int row, int col) { 
    return dataList.get(row).get(col);
    }

}

任何建议都是 jtable 的新手

4

1 回答 1

3

覆盖getColumnClass方法:

@Override
public Class<?> getColumnClass(int columnIndex) {
    if (isDate(columnIndex)) {
        return Date.class;
    }
    else {
        return String.class;
    }
}
于 2013-03-21T17:29:35.363 回答