Code Hungry
Code Hungry

Reputation: 4000

How to Display Output in Text Area in java

I am trying to display my output in Jtext Area.

while ((line1 = br1.readLine()) != null) {
    txt_output.append(line1+"\n");
    System.out.println(line1);
}

It gives me output once all the process finished. What want to show output execution line by line instead of all together.

please help me.....

Upvotes: 1

Views: 26732

Answers (3)

me_digvijay
me_digvijay

Reputation: 5502

I know the following method is very bad practice but you can try it for now

int temp = 0;
while ((line1 = br1.readLine()) != null) {
if(temp==0){
   txt_output.append(line1+"\n");
   temp = 1;
 }
 if(temp==1) {
  System.out.println(line1);
temp = 0;
}
}

Upvotes: 0

me_digvijay
me_digvijay

Reputation: 5502

You can possibly use the

textArea.setText();

method every time when you want the message to be printed. It automatically removes the previous text and writes the new one.

Upvotes: 0

vaisakh
vaisakh

Reputation: 1031

One similar post in Stackoverflow, deals with concurrency using threads.

Refer this one: Dynamically refresh JTextArea as processing occurs?

Upvotes: 1

Related Questions