Yes. You can use either of these approaches:
Use
getListDataListeners()
to get the listeners and transfer them to the new model.Use
removeAllElements()
and recycle the existing model.
Question
I have a combo box and I update its model with a new DefaultComboBoxModel
by calling setModel
. However when I first created the combo box, I registered an ItemListener
with it by calling addItemListener
. The problem is after I update the model, the ItemListener
no longer fires. Do I need to call addItemListener
with a new ItemListener
on my combo box after each time I update the model?
Solution
Yes. You can use either of these approaches:
Use getListDataListeners()
to get the listeners and transfer them to the new model.
Use removeAllElements()
and recycle the existing model.