Swing/JTable Not Updating After Bound Data Fires Change

前端 未结 4 1743
悲哀的现实
悲哀的现实 2021-01-22 18:16

I have a JTable which is bound to my EventTracker bean, essentially a wrapper around a list which I will use as append/clear only (i.e., a simple log). Problem is, when I add en

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-22 18:32

    It's not clear how you are binding the the EventTracker class to the table.I'm assuming you are using a corresponding editor and renderer class and then setting the render and editor like this table.setDefaultRenderer(EventTracker.class,new EventTrackerRender()); and table.setDefaultEditor(EventTracker.class,new EventTrackerEditor());.Editor is used in case only if you need to change the EventTracker bean through the table.

    If it done from outside the table (ie.through code) override the setValueAt function in the Table model and then get the EventTracker Object(which is the current object) using getValueAt and make necessary changes (if Eventtracker is mutable object).In case of immutable object make a new object of EventTracker and set it to the object array.After this you should either call fireTableDataChanged() which is going to repaint the whole table or call fireTableCellUpdated(row,col) for a particular cell to be rendered again.

提交回复
热议问题