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 3 of 3

Thread: Updating a Jlist from another thread problem

  1. #1
    Member
    Join Date
    Nov 2009
    Posts
    57
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default Updating a Jlist from another thread problem

    Hi

    I have a GUI that has a JList and a JListModel and then I have another thread which performs an action which updates the JListModel if it needs to.

    Now the problem is that the JList is not updated consistently everytime.

    I have looked up this issue and it is because the GUI should be always updated from the EDT thread.

    How can I refresh the GUI JList from another thread by calling it within the EDT?

    The same thread also updates the contents of a JLabel on the same GUI and this is updated everytime consistently, so is this really the problem?

    Thanks


  2. #2
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,102
    Thanks
    169
    Thanked 779 Times in 725 Posts
    Blog Entries
    5

    Default Re: Updating a Jlist from another thread problem

    Use a SwingWorker as the threading system, or use SwingUtilties.invokeLater (or invokeAndWait) to update. Always update GUI components on the EDT unless the API states the method is thread safe.

  3. The Following User Says Thank You to copeg For This Useful Post:

    mds1256 (August 11th, 2013)

  4. #3
    Member
    Join Date
    Nov 2009
    Posts
    57
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default Re: Updating a Jlist from another thread problem

    Thank you, used SwingUtilities.invokeLater and it works perfect each time

Similar Threads

  1. Updating JList
    By luigi10011 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 31st, 2013, 11:29 PM
  2. Jtble not updating using swing worker thread ?
    By harshilshah in forum AWT / Java Swing
    Replies: 2
    Last Post: April 26th, 2013, 09:10 AM
  3. Updating JList
    By KILL3RTACO in forum Java Theory & Questions
    Replies: 3
    Last Post: October 6th, 2011, 07:17 AM
  4. updating EDT with thread swingworker/invokeLater ?
    By mdstrauss in forum AWT / Java Swing
    Replies: 0
    Last Post: October 11th, 2009, 04:52 AM
  5. Replies: 0
    Last Post: October 10th, 2009, 01:25 PM