Reputation: 2128
I have a JList where each element holds some special data. So I have implemented AbstractListModel for the JList.
Everything works great when I have one or more elements in the list.
But, does not work in the scenario below:
I cannot call fire***() methods of AbstractListModel since it throws OutOfIndexException.
Any suggestions?
Upvotes: 1
Views: 860
Reputation: 285403
You state:
Because I am calling fireContentsChanged(this, 0,0)..which will look for 0th element in the list which does not exist. I know the cause but not the solution.
Don't call fireContentsChanged(...)
when removing items. Call fireIntervalRemoved(...)
instead. Also as an aside, you should never have to call repaint()
in this situation. Changing the state of the model and then notifying the model's listeners through a call to the proper fireXXX(...)
method is all that should be done.
Upvotes: 3