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.