Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception when updating JList within thread  RSS feed

 
Maxwell Fisher
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm working on a university assignment in distributed systems where we have to a implement a client software.

I have implemented a GUI in Swing which features a JList component showing the currently logged in users. I thought
it would be a good idea to have a thread update the list every second as new users log on and other users log off.
The method the thread calls looks like this:

This works fine for some time but eventually this exception will occur:

"gui_" is my Swing window class and "onlineUsersModel" is the DefaultListModel of the JList component.
Do you have any clues what the problem might be? Any help would be appreciated, thanks.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Maxwell and welcome to the Ranch! It rather looks like you're not aware of Swing's single threaded rule.

Wrap any call from another thread to a Swing component's method in a SwingUtilities.involeLater(...) and you should be good. If that doesn't help, consider posting a SSCCE that demonstrates your problem.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!