Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JTable + update date

843806Oct 3 2007 — edited Feb 19 2008
have tried my luck in new to java but no answers there so i'm double posting here in 'swing' forum

hey all!!
i have been battleing with tables and underlaying table models for a while now. i have posted a few questions before and subsequently (with the help of others) worked out pretty much everything i neede. so i have written my own table model, set the column widths dynamicaly, worked out how to update the table model and then database and so on.
now i have pretty much the last thing to work out and then my assignment will be sufficently coverd.
how do i update date fields (date of birth, start date etc) in a JTable (table model) ?? i have written my own table model (extension of AbstractTableModel) and it works fine. i can click on a field in the table and update it. but when i have date field i can't even click on. it seems as it is not updatable?? i get data from database as follows:
GetData.java
this is where i get my vectors that i use later to crreate the table
 for(int count=1;count<=rsMetaData.getColumnCount();count++){
                        switch(rsMetaData.getColumnType(count)){
                                case Types.VARCHAR:
                                case Types.LONGVARCHAR:
                                case Types.CHAR:
                                        row.addElement(resultSet.getString(count));
                                        break;
                                case Types.TIMESTAMP:
                                        row.addElement(resultSet.getTimestamp(count));
                                        break;
                                case Types.DATE:
                                        row.addElement(resultSet.getDate(count));
                                        break;
                                case Types.INTEGER:
                                case Types.SMALLINT:
                                        row.addElement(new Long(resultSet.getLong(count)));
                                        break;
                                case Types.DOUBLE:
                                case Types.NUMERIC:
                                        row.addElement(new Double(resultSet.getDouble(count)));
                                        break;
                                case Types.BIT:
                                        row.addElement(new Boolean(resultSet.getBoolean(count)));
                                        break;
                                default:
                                        row.addElement(rsMetaData.getColumnTypeName(count));
                        }
                }
 
then those vectors get passed to my table model
with getColumnClass to make the table better looking ((:
CustomTableModel.java
 public Class<?> getColumnClass(int col){
                return getValueAt(0,col).getClass();
        }
and after that i return the whole table (JTable) and grab it and put it where i want it.....

but as i said in the beginning i cannot update date fields in this table??!!
any suggestions, links to tuts, sample code??
thanks
v.v.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 18 2008
Added on Oct 3 2007
8 comments
146 views