Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / January 2006

Tip: Looking for answers? Try searching our database.

Forcing a JList to refresh one cell

Thread view: 
Paul Tomblin - 25 Jan 2006 21:41 GMT
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.

Signature

Paul Tomblin <ptomblin@xcski.com> http://xcski.com/blogs/pt/
I think I'd like to see a Simpsons episode starting up with Bart Simpson
writing 'I will not attempt to undermine the Usenet Cabal'.
             -- J. D. Falk

Oliver Wong - 25 Jan 2006 21:51 GMT
>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
Vova Reznik - 25 Jan 2006 21:53 GMT
> 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.

Look in
javax.swing.AbstractListModel
and its method
protected void fireContentsChanged(Object, int, int)

Practically you'll need to create your own model extends
AbstractListModel if you don't have one.
Paul Tomblin - 25 Jan 2006 22:36 GMT
In a previous article, Vova Reznik <address@mail.com> said:
>> I have a JList where each item in the list is rendered by a
>> ListCellRenderer.  Among other things, the ListCellRenderer shows a
[quoted text clipped - 10 lines]
>Practically you'll need to create your own model extends
>AbstractListModel if you don't have one.

In order to do that, the item would have to propogate the fact that it
changed up to the ListModel, and then the ListModel would have to
fireContentsChanged.  I was hoping there was a direct way, but I guess
that will do.

Signature

Paul Tomblin <ptomblin@xcski.com> http://xcski.com/blogs/pt/
You had me at
   print("Hello World\n");



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.