Posted Thursday, April 13, 2006 @ 10:31:04
i'm using your quicktable and the component date from javadatepicker (www.javadatepicker.com , you can download a demo version on this site)
and the problem is when i make a cellEditor for this date field into your table !
Everything is ok (selecting a date) but not when the date selected is null. The table is putting the old date again back when i leavec the cell editor ! ! ! and before leaving the cell, i have - - and when i leave, i have the old date back ! ! !
I have try since 2 days and it's not working. JavadatePicker says that the problem must be in your component.
Here is a sample ... Could you told me what to do ?
thank in advance
public class myMain extends JFrame
{
public myMain ()
{
//OrderModel myCellModel = new OrderModel();
MyCellListener cellListner = new MyCellListener();
CellPropertiesModelDefault cellProp = new CellPropertiesModelDefault();
//set Frame properties
setSize(300,200);
setVisible(true);
//create a new quicktable
quick.dbtable.DBTable dBTable1 = new quick.dbtable.DBTable();
//add to frame
getContentPane().add(dBTable1);
//set the database driver to be used, we are using jdbc-odbc driver
dBTable1.setDatabaseDriver("sun.jdbc.odbc.JdbcOdbcDriver");
/*
set the jdbc url,"quicktabledemo" is the data source we have created
for the database
*/
dBTable1.setJdbcUrl("jdbc:odbc:quicktabledemo");
// set the select statement which should be used by the table
dBTable1.setSelectSql("select * from employee");
//to create the navigation bars for the table
dBTable1.createControlPanel();
dBTable1.addTableCellListener(cellListner);
dBTable1. setCellPropertiesModel(cellProp);
try
{
//connect to database & create a connection
dBTable1.connectDatabase();
//fetch the data from database to fill the table
dBTable1.refresh();
dBTable1.createColumnModelFromQuery();
Column colonne = dBTable1.getColumn(3);
colonne.setUserCellEditor(new CellEditorDate());
}
catch(SQLException e)
{
e.printStackTrace();
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
}
class MyCellListener implements DBTableCellListener
{
public Object cellValueChanged(int row, int col, Object oldValue, Object newValue)
{
return newValue;
}
}
public class CellPropertiesModelDefault extends CellPropertiesModel implements Serializable
{
public int getCellEditable(int row, int col)
{
return 1;
}
}
public static void main(String[] args)
{
//create a new table frame
myMain myframe = new myMain ();
}
}
public class CellEditorDate implements CellComponent
{
JDatePicker j = new JDatePicker();
public void addActionListener(ActionListener arg0)
{
// TODO Auto-generated method stub
}
public JComponent getComponent()
{
// TODO Auto-generated method stub
return j;
}
public Object getValue()
{
// TODO Auto-generated method stub
return j.getSelectedDate();
}
public void setValue(Object arg0)
{
if (arg0==null)
j.setSelectedDate(null);
else
j.setSelectedDate((java.util.Date)arg0);
}
}