System.out.println output in JTextArea

I would like every time I call System.out.println, adding to this JTextArea, without having to change all the calls to System.out.println ... Is this possible?

Thanks.

+3
source share
4 answers

Versions of Java with 1.5 have System.setOut()that allow you to install your own PrintStream. Just create a simple OutputStreamone that adds the data that it receives through write()Then wrap it in PrintStreamand install.

+11
source

Well you can do it using the method jTextArea.append("Your String")

+1
source

, . System.out . () MyUtil.myOutput(), ,

0
source

Suppose you could use some form of AspectJ , but I think it might be redundant. What I would do is create a method that will print and add.

public void printAndAppend(String text) {
      System.out.println(text);
      textArea.append(text);
}

Then you can simply do a global find and replace for System.out.printlnand replace it withprintAndAppend

-1
source

Source: https://habr.com/ru/post/1724124/


All Articles