Update JTextField from another thread in Java

client, java, multithreading, swing, user-interface

Solution

I don't know where you heard about "SwingUtilities creates a new thread" from, but I think you've either misunderstood or being informed incorrectly. `SwingUtilities.invokeLater` places the `Runnable` onto the end of the Event Dispatcher's queue. The queue then processes this event within the it's own thread context (in time), calling `Run`, there is no "new" thread created for this process.

As to your question.

You may need to call `validate()` (and possibly `repaint()`) on the fields parent container to encourage it update ;)

And no, there isn't any other way to sync the UI across threads, that's the reason for `SwingUtilities`

Problem

I'm making a game client/server and I'm having a new thread update some info on the client GUI (which is using Swing). I'm trying to use SwingUtilities but it's not working. Also, I heard SwingUtilities creates a new thread everytime you use it so I'm looking for a new way as well (I have 10 or so JTextFields to be updated). Is there a way to do it without using SwingUtilities? Here is what I have right now. ``` SwingUtilities.invokeLater( new Runnable() { public void run() { Client.status.setText("status = "+status); } }); ```

Original source