JTable Java Error Stack OverFlow when setvalue to a specific column

后端 未结 1 880
庸人自扰
庸人自扰 2021-01-24 17:22

This is my Code below. I have created a Jtable with 4 column and 3 rows. and add table model listener, In the Table change Listener, When i set the value in a particular column

1条回答
  •  情话喂你
    2021-01-24 17:38

    JTable#setValueAt will call TableModel#setValueAt, which will trigger a TableChanged event, which is why it's causing you a StackOverflowException (it's caught in an infinite loop)

    The better solution would be to override the TableModel#setValueAt and if the column 0, 1 or 2 is updated, also calculate the value for column 3, but don't forget to fire a cellUpdated event

    0 讨论(0)
提交回复
热议问题