Hello. On button click, I have some loop and inside it I want to append jTextArea with some data. I want to do it for example every 3 seconds. For example:
answer1 printed 11:13:10
answer1 printed 11:13:13
answer3 printed 11:13:16
answer4 printed 11:13:19
and so on.
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { if (kiek > 0 && jTextArea1.getLineCount() > 0) { String str; BufferedReader reader = new BufferedReader( new StringReader(jTextArea1.getText())); double prog = 0; try { while ((str = reader.readLine()) != null) { if (str.length() > 0) { jTextArea2.append("---------------------\n"); jTextArea2.append("Working with IP " + str + "\n"); for (int j = 0; j < a.size(); j++) { jTextArea2.append(a.get(j) + "\n"); } } prog += (double) 100 / (double) jTextArea1.getLineCount(); jProgressBar1.setValue((int) (prog)); } } catch (IOException ex) { } } }
I get each line of other TextArea, print it to current, and also add some information from ArrayList a jTextArea2.append(a.get(j) + "\n");
All I want is that every output to textarea would be periodical for example for 3 seconds.
I tried to do it with Thread.pause(); but in that way, it is waiting for all function to end, and then outputs all data in one time.