Im having a problem displaying text in JTextPane. I want to be able to append text (e.g. "Task 1 completed..") after a task is completed. But mine display the text once all the tasks are completed which is quite useless as user does not know what is going on. I know this has something to do with thread n stuff.. but im not quite sure.. any help is greatly appreciated..


It would help if you could post some of the source code your using. Can then maybe evaluate the logic a bit more.

here is the partial section of my code

styledDoc.insertString(styledDoc.getLength(), "Removing previous file..", highlight);

        styledDoc.insertString(styledDoc.getLength(), "\n", defaultformat);

         styledDoc.insertString(styledDoc.getLength(), "Time taken: "+(System.currentTimeMillis()-startTime)+" miliseconds.", medium);

Basically I want to append text message to my JTextPane object every time a task is completed. But all messages got displayed after the last task is executed. I want after task A is completed, then append "Task A is completed.." then do task B, prints "Task B is completed"... and so on.. I explicitly put the code in sequence as you can see from the attached code here... I read somewhere about this problem. To solve one need to use Thread. But im not sure how..

Hm you could try the following

String text;
text = textPane.getText();
text += "\nAppended text."

But i think that there is a better way to do it.