I want to add delay in displaying text in a textArea. I use Thread.sleep method but it is not working properly.
for(int i=0; i<3; i++) {
textArea.append(" .");
Thread.sleep(2000);
}
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.
However if I use this part of code in a simple java class other than GUI then it work totally fine.
Please help me how can I do this?