First of all if your columns contain numbers then you should store the Double
value in the model, not a String.
So you need to override the getColumnClass(...)
method of your TableModel
to tell the table the type of data stored in the column so the table can use the appropriate renderer/editor.
Some thing like:
@Override
public Class getColumnClass(int column)
{
switch (column)
{
case 0: return Double.class;
case 3: return Double.class;
case 6: return Double.class;
default: return Object.class;
}
}
You would also override the isCellEditable(...)
method to prevent data in column 6 from being edited, since its value will always be the result of values found in columns 0 and 3.
when someone enters a value
Whenever data is changed in the table the TableModel is updated.
So one approach is to override the setValueAt(...)
method of your TableModel to recalculate the value for column 6.
The basic logic would be:
@Override
public void setValueAt(Object value, int row, int column)
{
super.setValueAt(value, row, column);
if (column == 0 || or column == 3)
{
double column0 = getValueAt(row, 0);
double column3 = getValueAt(row, 3);
double result = column0 * column3;
setValueAt(result, row, 6);
}
}
Read the section from the Swing tutorial on How to Use Tables for more information.