Vini,
E com esta classe que você fala né ?:
public class TextComponentStream extends OutputStream {
private JTextComponent textComponent;
private Style error;
public TextComponentStream(JTextComponent textComponent, Style error) {
this.textComponent = textComponent;
this.error = error;
}
public void println(String text) {
print(text + "\n");
}
public void print(String text) {
try {
write(text.getBytes());
}
catch (IOException e) {
//Faça o log da exceção aqui
}
}
@Override
public void write(final int b) throws IOException {
write(new byte[] {(byte) b}, 0, 1);
}
@Override
public void write(final byte[] b, final int off, final int len)
throws IOException {
final String str = new String(b, off, len);
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
textComponent.getDocument().insertString(
textComponent.getDocument().getLength(), str, error);
}
catch (BadLocationException e) {
//Faça o log da exceção aqui
}
}
});
}
@Override
public void flush() {}
@Override
public void close() {}
}
E para usá-la, usa-se isso:
public Style getErrorStyle()
{
Style style = getTxtPane().getStyledDocument().addStyle("error",
null);
StyleConstants.setForeground(style, Color.red);
return style;
}
//Mais tarde...
System.setOut(new TextComponentStream(getTxtPane(), null));
System.setErr(new TextComponentStream(getTxtPane(), getErrorStyle());
Agora, só desculpa a minha ignorância, como posso passar os meus “System.out” para serem impressos no JTextArea com esta classe?
Não consegui entender o código a fim de descobrir a maneira de fazer com que seja possível ler minhas mensagens conforme abaixo:
txtArea.setText("Lendo o arquivo : " + " " + arquivos[i].getName() + "\n");
Obrigado