I have this game using a Client & Server with sockets. When a client starts it requests a Room list of all currently available Rooms which then the client puts in a JList using a DefaultListModel. Then when the client selects one of the Rooms it sends a request to the Server to join this Room. Then the Server replies back with an Object containing all the Players that are currently in this Room. The client then updates the JList like this:
As you can see basically all the current elements currently in the DefaultListModel are removed and then the newly received Players are added to the DefaultListModel.
But sometimes the JFrame does not update the JList properly and it appears empty but it did printout the message "..... added to the Playerlist"..
Example: Player A connects to the Server and joins Room 0. Now the JList is always gets updated properly!! Then Player B connects to the server and joins Room 0 as well. Then the server broadcasts the current players in Room 0 back to the Clients(Player A and B).
Player A does receive the update(according to the printed out console messages) but the JList is not updated(this is actually where the problem occurs but it does not always happen!).
Player B also receives the update and the JList is always updated properly.
Joined: Jun 09, 2003
> Player A does receive the update(according to the printed out console messages) but the JList is not updated
possible symptom of blocking Swing's EDT
Joined: Jun 13, 2009
this is actually where the problem occurs but it does not always happen!
Whenever I see random behavour I always guess that you are not updating your Swing component on the EDT.
If you are doing Client/Server processing, then somewhere you need to invoke SwingUtilities.invokeLater(...) to place the list update code on the EDT.