I have created a swing ui and redirected System.out and System.err to a text field with this code
ConsoleOutputStream cos = new ConsoleOutputStream(textColor, printStream);
System.setOut( new PrintStream(cos, true) );
ConsoleOutputStream extends ByteArrayOutputStream, and as long as nothing is executed in new threads this works as expected.
However, my application executes third party jar files which in turn creates new threads. When these threads print to System.out it gets printed in the terminal that launched my application instead of in my text field. I have looked at this link: http://maiaco.com/articles/java/threadOut.php but i'm not sure it's applicable to my problem since I have no control whatsoever over the threads. As far as my application is aware no threads (except for the main gui thread) are created.
Is there some way to redirect all System.out:s and System.err:s independent of the threads? If not, can I maybe listen to calls to System.out and then print them to my text field? Could I potentially listen to the terminal that I launched my application from and redirect all output from it to my application?