Re: Forcing a JList to refresh one cell




"Paul Tomblin" <ptomblin+netnews@xxxxxxxxx> wrote in message
news:dr8r9d$2mo$1@xxxxxxxxxxxxxxxxxxxx
>I have a JList where each item in the list is rendered by a
> ListCellRenderer. Among other things, the ListCellRenderer shows a
> JProgressBar that is updated by an outside event. The item itself has an
> observer to notice that it has been updated, but other than calling
> repaint on the whole JList, I can't seem to make it repaint the cell that
> changed.

Hopefully, you have a javax.swing.ListModel representing all the items
in your list. This ListModel should be keeping track of its
javax.swing.event.ListDataListeners, of which the JList itself is probably
one of the listeners.

You should send your ListDataListeners a "contentsChanged" notification
and provide it with a javax.swing.event.ListDataEvent to tell it
specifically which elements has changed in the list.

See:
http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/ListModel.html
http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/event/ListDataListener.html
http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/event/ListDataEvent.html

- Oliver


.



Relevant Pages

  • Re: Forcing a JList to refresh one cell
    ... >> ListCellRenderer. ... >> repaint on the whole JList, I can't seem to make it repaint the cell that ... >protected void fireContentsChanged(Object, int, int) ... changed up to the ListModel, and then the ListModel would have to ...
    (comp.lang.java.gui)
  • Forcing a JList to refresh one cell
    ... ListCellRenderer. ... JProgressBar that is updated by an outside event. ... repaint on the whole JList, I can't seem to make it repaint the cell that ... I think I'd like to see a Simpsons episode starting up with Bart Simpson ...
    (comp.lang.java.gui)