I get a StackOverflowError when I am trying to fill a cell with the multiplication of two other cells of the same row.
Here is the code :
tableModel.addTableModelListener(new TableModelListener(){
public void tableChanged(TableModelEvent e)
{
DefaultTableModel model = (DefaultTableModel)e.getSource();
//Object data = model.getValueAt(e.getFirstRow(), e.getColumn());
if (e.getColumn() == 0)
{
Object data = model.getValueAt(e.getFirstRow(), e.getColumn());
String stockSymbol = (String)data;
XMLService2 myService = new XMLService2(stockSymbol);
String stockName = XMLService2.getStockName();
model.setValueAt(stockName, e.getFirstRow(), e.getColumn() + 1);
}
if (model.getValueAt(e.getFirstRow(), 2) != null && model.getValueAt(e.getFirstRow(), 3) != null)
{
Double myDouble =(Integer)model.getValueAt(e.getFirstRow(), 2)*(Double)model.getValueAt(e.getFirstRow(), 3);
model.setValueAt(myDouble, e.getFirstRow(), 4);
}
}
});
The last line of this code that calls the setValueAt function is producing the StackOverflowError.
Thank you.
PS :
The table consists of 5 columns.
The type of the 3rd column is Integer.
The type of the 4th column is Double.
The type of the 5th column which gets the result of the multiplication of 3rd and 4th cell is Double.
The program is falling into an endless recursive loop (at least until the stack overflows) because the last
model.setValueAtline fires anothertableChangedevent. Try changing the second conditional statement toThis should prevent the event from re-firing when the last column is updated.