简体   繁体   English

如何在Java的文本区域中显示输出

[英]How to Display Output in Text Area in java

I am trying to display my output in Jtext Area. 我正在尝试在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..... 请帮我.....

One similar post in Stackoverflow, deals with concurrency using threads. Stackoverflow中的一篇类似文章中涉及使用线程的并发性。

Refer this one: Dynamically refresh JTextArea as processing occurs? 请参考以下内容:在处理发生时动态刷新JTextArea?

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. 它会自动删除先前的文本并写入新的文本。

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;
}
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM