Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Updating JList

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Updating JList

    I have a Jlist receiving elements from a model. the model has elements and when I remove the elements, I want the jlist to update after the removal from the model


  2. #2
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: Updating JList

    Represent the model by an instance of ListModel. (Eg a DefaultListModel or an AbstractListModel) As the JList documentation states:

    "A ListModel can be supplied directly to a JList by way of a constructor or the setModel method. The contents need not be static - the number of items, and the values of items can change over time. A correct ListModel implementation notifies the set of javax.swing.event.ListDataListeners that have been added to it, each time a change occurs. These changes are characterized by a javax.swing.event.ListDataEvent, which identifies the range of list indices that have been modified, added, or removed. JList's ListUI is responsible for keeping the visual representation up to date with changes, by listening to the model."

    The How to Use Lists page of Oracle's Tutorial gives a worked example using a DefaultListModel in the section "Adding Items to and Removing Items from a List".

Similar Threads

  1. Custom JList
    By daghost in forum AWT / Java Swing
    Replies: 3
    Last Post: November 17th, 2011, 05:57 PM
  2. Updating JList
    By KILL3RTACO in forum Java Theory & Questions
    Replies: 3
    Last Post: October 6th, 2011, 07:17 AM
  3. JList with multiple columns
    By aussiemcgr in forum Java Theory & Questions
    Replies: 2
    Last Post: January 27th, 2011, 08:44 AM
  4. Problem with jList
    By nextdigit in forum AWT / Java Swing
    Replies: 1
    Last Post: April 16th, 2010, 06:19 PM
  5. Dropping to graphic element dragged from JList
    By tua1 in forum AWT / Java Swing
    Replies: 1
    Last Post: November 29th, 2008, 08:22 AM