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]
# 1
How and where exactly do you begin to programaticly edit the cell, do you use any modified classes ?some source code would be nice.Mr Mean
Mr Mean at 2007-6-29 2:25:28 > top of Java-index,Archived Forums,Swing...
# 2

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];

}

}

tseowf at 2007-6-29 2:25:28 > top of Java-index,Archived Forums,Swing...
# 3
I don't quite get why you create a new DataModel in your tellmethetime method. How does it co-relate to the the datamodel you used for constructing your JTable ?That could be the problem.
shirish_wagh at 2007-6-29 2:25:28 > top of Java-index,Archived Forums,Swing...
# 4
Thanks alot shirish wagh.So new DataModel in my tellmetime method is causing all the problem.
tseowf at 2007-6-29 2:25:28 > top of Java-index,Archived Forums,Swing...