I successfully redirected the System.out
and System.err
to the JTextArea followed this article: https://www.codejava.net/java-se/swing/redirect-standard-output-streams-to-jtextarea.
But the both type of messages displayed in same font color. I want the System.err messages shows in red color, and the System.out messages shows in defined foreground color (currently white). Is it possible?
No, this is not possible. A JTextArea is a simple text component that can only show one font and one font color. If you need more complexity, you need to use a more complex, powerful (and difficult to use) component, such as a JTextPane or JEditorPane.
Another option is to use a JList to display the text from the system, and give it a renderer to that it knows to display normal messages in black and err messages in red. This can be made to look like a JTextArea, but does have some difficulties if an individual message takes up more than one line.