Problem with JTable
I tried to update some values to a particular cell of the JTable but it doesn't show the updated value.
I tried using the fireTableCellUpdated() but it doesn't seems to work.
any idea how to show the updated value without having to refresh the whole table?
Thanks alot!
[310 byte] By [
tseowf] at [2007-9-26 1:38:00]

I tried to update the row 1 column 2 of the cell every 2 sec from the server by the tellMeTheTime(Date d)method but it doesn't seems to update the table at all.
attach is part of the source code.
public class RMIApplet extends JApplet implements TimeMonitor
{
public void init()
{
super.init();
DataModel datamodel = new DataModel();
JTable table = new JTable(datamodel);
table.sizeColumnsToFit(false);
JScrollPane pane = new JScrollPane(table);
getContentPane().add(pane, BorderLayout.CENTER);
}
public void tellMeTheTime(Date d)
{
String value = d.toString();
System.out.println("Current Date is: " + value);
DataModel datamodel = new DataModel();
datamodel.getValueAt(1,2);
datamodel.setValueAt(value, 1, 2);
}
}
class DataModel extends AbstractTableModel
{
String columns [] = {"Column1", "Column2", "Column3", "Column4"};
String rows [][] = {
{"01/05/01", "01", "01", "1100"},
{"02/05/01", "02", "02", "1200"},
{"03/05/01", "03", "03", "1300"},
{"04/05/01", "04", "04", "1400"},
};
private int numColumns = columns.length;
private int numRows = rows.length;
public int getColumnCount()
{
return numColumns;
}
public int getRowCount()
{
return numRows;
}
public Object getValueAt (int row, int column)
{
return rows [row][column];
}
public void setValueAt (Object aValue, int row, int column)
{
String cellValue;
if(aValue instanceof String)
cellValue = (String)aValue;
else
cellValue = aValue.toString();
//rows [row][column] = cellValue;
//fireTableChanged (new TableModelEvent (this, row));
rows [row][column] = cellValue;
fireTableCellUpdated(row, column);
}
public String getColumnName (int columnIndex)
{
return columns[columnIndex];
}
}