Swing/JTable Not Updating After Bound Data Fires Change

前端 未结 4 1744
悲哀的现实
悲哀的现实 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:51

    I was really intent on getting the data binding working. The answers recommended were good reading, but would have led me to writing a lot of code. I didn't want to handle giving the row count/column count logic and all that extra work. As a result, this solution may provide less control but it's pretty quick and easy for this read-only workflow.

    The document at http://swinglabs.org/docs/presentations/2007/DesktopMatters/beans-binding-talk.pdf gave me the skinny. The trick was to use ObservableCollection / ObservableList(new ArrayList) as the datastore. Whenever I add another entry it is automatically reflected in the JTable.

    Great!

提交回复
热议问题