Update Java Swing component from a background thread
<p>I am working on a project for receiving data from client sockets. The user interface contains a Text Area to show the received data. <br>
What is the best way to pass the received data from the servers threads back to text area? <br>
Currently what i do is the following.</p>

<ol>
<li>start the JFrame Java Application</li>
<li>Create a Server object and pass the JTextArea object to it.</li>
<li>Start the socket server in a separate thread</li>
<li>when new message received form a client, the thread update the JTextArea field like following</li>
</ol>

<p></p>

<pre><code>jtextarea.setText(newMessage);
</code></pre>

<p>Is my approach correct?</p>