redirect console output to a JTextArea

Discussion in 'Plugin Development' started by TheUnnamedDude, Nov 4, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    TheUnnamedDude

    hello, im making a simple GUI as plugin to bukkit. But i don't know how to redirect the output to the Textbox :(

    Thanks TheUnnamedDude
     
  2. Offline

    Acrobot

  3. Offline

    TheUnnamedDude

    The GUI is done, i only need to get the output into the textbox.
    is there another way to get the output without messing with the cmd console?

    If you want to se what i got so far: Link

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 21, 2016
  4. Offline

    Acrobot

  5. Offline

    TheUnnamedDude

    i tryed that, but almost everything in the console is gone when i do it. i want a way that don't affect the normal console :)
     
  6. Offline

    hatstand

    Use that method, then pass the stuff back to the original OutputStream

    In case you're boring (open)

    Code:java
    1. private static void redirectSystemStreams() {
    2. final PrintStream oldOut = System.out;
    3. OutputStream out = new OutputStream() {
    4. @Override
    5. public void write(final int b) throws IOException {
    6. updateTextPane(String.valueOf((char) b));
    7. oldOut.write(b);
    8. }
    9.  
    10. @Override
    11. public void write(byte[] b, int off, int len) throws IOException {
    12. updateTextPane(new String(b, off, len));
    13. oldOut.write(b, off, len);
    14. }
    15.  
    16. @Override
    17. public void write(byte[] b) throws IOException {
    18. write(b, 0, b.length);
    19. }
    20. };
    21.  
    22. System.setOut(new PrintStream(out, true));
    23. System.setErr(new PrintStream(out, true));
    24. }

     
  7. Offline

    TheUnnamedDude

    Thank you, just what i looked for :)
     
Thread Status:
Not open for further replies.

Share This Page