Add listener to ArrayList

前端 未结 8 1332
再見小時候
再見小時候 2020-12-09 17:14

I have an ArrayList which I add some Objects to it dynamically, and I have a JButton. The ArrayList is empty when running my program and the JButton is set to setEnabled(fal

8条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-09 17:33

    ArrayList doesn't have any sort of notification mechanism.

    I suggest you write your own List implementation which delegates to a private ArrayList for its storage, but adds the ability to listen for notifications... or find something similar within Java itself. DefaultListModel may work for you, although it doesn't implement List itself.

提交回复
热议问题