How to add delay inside a JTextArea in displaying text?
<p>I want to add delay in displaying text in a textArea. I use Thread.sleep method but it is not working properly.</p>

<pre><code>for(int i=0; i&lt;3; i++) {
    textArea.append(" .");
    Thread.sleep(2000);
}
</code></pre>

<p>This part of code is inside the actionListner of a button. When button is pressed a single dot(.) is displayed inside the textArea each by 2 sec delay but the loop is not working correctly. When I run the code the program first wait for 6 seconds then the whole output is shown at once in the textArea.</p>

<p>However if I use this part of code in a simple java class other than GUI then it work totally fine.</p>

<p>Please help me how can I do this?</p>