I implemented my own ListCellRenderer for my chat app. I use a JList to list all users. The cell renderer consists mainly of an icon that displays if a particular user is currently on- or offline and his/her name. The list is controlled by a DefaultListModel which I use to provide the JList with the necessary information.
But when the list model does change its state (e.g. a user goes offline), the list cell renderer seems not to be invoked?
Somebody any idea how to solve this problem? Tried to call updateUI() on the JList instance, but did not helped.
Many thanks in advance!
The cell renderer probably works fine. What is not working is the ListModel. The DefaultListModel
does not detect changes to the internal state of the model objects. You need to call fireContentsChanged
on the list model. Probably you need to add listeners to your model objects and maybe you even have to extend the DefaultListModel
; as I don't see the code of it I don't know how yours look.
You should not just call a random method with a name that sounds good (updateUI
does something very different).