Redirecting stdOut to a JTextArea - Help!

I want to redirect stdOut via System.setOut to a JTextArea - I'm most of the way there but I keep getting some strange errors. I'd really appreciate some help!
I have a class called MainDebug which in its constructor calls
System.setOut(new DebugStream((OutputStream)System.out));
it also has a method
public void appendMessage(String message)
txtAreaDebug.append(message);
where txtAreaDebug is the JTextArea to which I want to redirect stdOut.
In MainDebug is another class called DebugStream (which is referred to in MainDebug's constructor). The entirety of that class is as follows:
public class DebugStream extends java.io.PrintStream
public void println(String x)
MainDebug.this.appendMessage(x);
public void write(int x)
MainDebug.this.appendMessage(new Integer(x).toString());
When I build I get these errors:
pcgen\gui\MainDebug.java:63: cannot resolve symbol
symbol : constructor DebugStream (java.io.OutputStream)
location: class pcgen.gui.MainDebug.DebugStream
System.setOut(new DebugStream((OutputStream)System.out));
^
pcgen\gui\MainDebug.java:166: cannot resolve symbol
symbol : constructor PrintStream ()
location: class java.io.PrintStream
public class DebugStream extends java.io.PrintStream
For the first error, shouldn't DebugStream inherit the proper constructor from PrintStream? And I have no clue about the second error - I believe I've extended the class correctly.
Pearls of wisdom appreciated! :)

Constructors aren't inherited from superclasses, so you'll need to supply your own constructor for DebugStream.
FWIW, I've done this before and here's my version of DebugStream:
   private class MyPrintStream extends PrintStream
      public MyPrintStream(OutputStream pOut)
         super(pOut);
      public void println(String pString) {
         if (mResultsPanel != null)
            mResultsPanel.append(pString);
         super.println(pString);
      public void println(Object pObject)
         if (mResultsPanel != null)
            mResultsPanel.append(pObject.toString());
         super.println(pObject);
   }where mResultsPanel has a reference to the JTextArea.
Good luck,
Tom

Similar Messages

  • Redirecting stdout in 64 bit mode

    Hi,
    I have a problem. I wanted to redirect stdout to a text file and back. In 32 bit mode everything works fine using file member to struct FILE, but in 64 bit mode only data member FILE has long _pad[16]. Can anyone tell me how to use this to redirect stdout to file and visevesra. Thanks in advance.
    Amandeep

    By default in 10.6.8 it should be in 64 bit mode but to check and change it in Finder highlight Aperture, the application, and go command I to open the info window and look about 1/4 of the way down
    (Note this is from Lion so it is slightly different then what you will see)

  • Redirecting stdout of third party API?

    Good Morning (or afternoon),
    I have an interesting problem with an application that I am writing.
    I am using my own classes, as well as a third party package that somebody developed, in this application.
    I have developed a GUI for ease of use and in this GUI I have a textarea component that shows all stdout messages.
    To achieve this I simply used System.setOut(PrintStream out) to redirect the output to my textarea. Now, all stdout messages display on my textarea. So far so good.
    The problem came when I used the third party package. The third party stdout still goes to the default (terminal).
    I have to use the third party package through it's main method so I am calling ThirdPartyPackage.main(thingToPass).
    Does anyone know why this occurs, or how I can get the third party classes to use the stdout that is currently in use by the calling class?
    I am very stuck and would really appreciate any help even theoretical.
    Thankyou in advance.

    I am doing exactly the same thing, here's the code that calls an external process and appends the output to a JTextArea:
    (txtOutput is the JTextArea I'm showing the output in)
              try
                   Process proc = Runtime.getRuntime().exec(progName);
                   InputStream procStdout = proc.getInputStream();
                   InputStream procStderr = proc.getErrorStream();
                   int exit = 0;
                   boolean processEnded = false;
                   while(!processEnded)
                        try
                             exit = proc.exitValue();
                             processEnded = true;
                        catch(IllegalThreadStateException e) {} // still running
                        int n = procStdout.available();
                        if(n > 0)
                             byte[] pbytes = new byte[n];
                             procStdout.read(pbytes);
                             //System.out.print(new String(pbytes));
                             //System.out.flush();
                             txtOutput.append(new String(pbytes));
                             txtOutput.setCaretPosition(txtOutput.getText().length());
                        n = procStderr.available();
                        if(n > 0)
                             byte[] pbytes = new byte[n];
                             procStderr.read(pbytes);
                             System.err.print(new String(pbytes));
                             System.err.flush();
                        try
                        Thread.sleep(10);
                        catch(InterruptedException e) {}
                   System.out.println();
                   System.out.println("Process exited with: " + exit);
              catch (java.io.IOException e)
                   System.out.println(e.toString());
              }

  • Redirecting process output to jtextarea

    I'd like to redirect the output of a process to a JTextArea that is continuously updated as the output comes in. Can anyone help me with this?

    I'm basically confused as to how to do this.
    I have the following class that I obtained from a site.
    There's an example posted as to how to redirect system error ouput to a JTextArea using the Stream class below. I want to take the ouput of a launched process, and send it to a textarea.
    import java.io.IOException;
    import java.io.OutputStream;
    import javax.swing.JTextArea;
    public class TextAreaOutputStream extends OutputStream{
           private JTextArea textArea;
           private StringBuffer buff;
           public TextAreaOutputStream(JTextArea textArea){
             this.textArea = textArea;
             this.buff = new StringBuffer();     
           public void write(int b)throws IOException{
             // this next line is kind of a hatchet job... it works... but still
             buff.append(Character.toString((char)b));
             if(buff.length()>100){
               flush();     
           public void flush()throws IOException{
             this.textArea.append(buff.toString());
             this.buff = new StringBuffer();
           public void close()throws IOException{
             this.textArea = null;
             this.buff = null;
         }So I'd like to launch my process, and direct all output from that process to a Jtextarea? Is there a rough overview anyone can give me as to how this can be done?

  • Redirect stdout to null

    Hi,
    can you redirect stderr and stdout of servants to /dev/null?
    I'd like to avoid the overhead of writing to the stdout files.
    Thanks,
    Juergen

    Hi,
    probably you can try the two options in each server's command line option:
    http://edocs.bea.com/tuxedo/tux100/rf5/rf5.html#wp1003290
    [-e stderr_file]
    [-o stdout_file]

  • Redirecting stdout and stderr when starting a MS with the NM

    We are looking at using the Node Manager for stopping and starting the managed servers in some of our projects, to give the testers/developers the ability with operator role in the WLS console to save them calling someone.
    The only trouble is, with our existing shell start scripts we redirect shell level stdout and stderr to a file, i.e
    nohup ./startManagedWebLogic.sh test1-ms11 >> $OUTFILE 2>&1 &
    But how do you do the same when starting the same managed server using the node manager and the WLS Admin Console??
    There is the argument "-Dweblogic.log.RedirectStdoutToServerLogEnabled=true", but this only redirects on the JVM level.
    Is there a way around this problem to get the node manager outputing the same as our scripts do.
    Any direction would be great.
    Alistair.

    Gene
    Thanks for the replies and additional information.
    I was almost sure that one of the previously suggested troubleshooting steps would solve the problem but unfortunately that was not the case.
    So, let us look at the following factors....
    1. Delete the Adobe Premiere Elements Prefs file and, if that does not work, then delete the whole 12.0 Folder in which the Adobe Premiere Elements Prefs file exists.
    Local Disk C
    Users
    Owner
    AppData
    Roaming
    Adobe
    Premiere Elements
    12.0
    and in the 12.0 Folder is the Adobe Premiere Elements Prefs file that you delete. If that does not work, then you delete the whole 12.0 Folder in which the Adobe Premiere Elements Prefs file exists. Be sure to be working with Folder Option Show Hidden Files, Folders, and Drives active so that you can see the complete path cited.
    2. Try to open the Premiere Elements 12 Editor from its Adobe Premiere Elements.exe file rather than desktop icon which uses Adobe Premiere Elements 12.exe file.
    Local Disk C
    Program Files
    Adobe Premiere Elements 12
    and in the Adobe Premiere Elements 12 Folder is the Adobe Premiere Elements.exe file that you double click to open the Premiere Elements 12 Editor bypassing the Welcome Screen. If necessary, we could create a desktop shortcut for the Adobe Premiere Elements.exe file for future use to open the program.
    Also, look at the necessity to right click the desktop icon for the program and the .exe files and apply Run As Administrator to each even if you are running the program from a User Account with Administrative Privileges.
    3. Consider creating a new User Account with Administrative Privileges and install and running Premiere Elements 12 in it (I would save this consideration for the last.)
    Please review. We will be watching for the results.
    Thank you.
    ATR

  • Random linkbucks redirect issie...please help!

    Hello,
    I've got this strange redirect issie in all my web browsers, and think I may have a trojan or a virus. It's driving me mad, please somone help! I'm running OSX 10.6.8 with Firebox and Chrome.
    When I click a link on random sites it redirects me to an irellevant URL + advertising: linkbucks.com... [followed by the adress of the intenended site]
    This occures when leaving the page you are on (e.g. changing page on the site you are viewing). It happens on any site and appears to be compeltly random.
    Is this a virus/trojan? If so, how can I get rid of it?
    Thank you very much.
    Ben

    THIS IS A BROWSER REDIRECTION INFECTION
    No known Malware Protection/detection will help!
    How it works:  You pick it up on a web site and it then infects your browser.
    It rapidly spreads to your wifi hub and the many other items of your network infrastructure
    Finding for the hidden/embedded infection files is near impossible
    REMOVAL
    Close Down WiFi
    Remove any RG45/CAT5 Connection
    Delete Completely - all traces of: Firefox, Opera and Chrome
    Reset Safari using Shift + Alt + Reset
    Re-Install Firefox, Opera and Chrome
    POWER DOWN every item on your network
    Reboot Your Network
    Reconnect WiFi and test
    IFF it is normal :-)
    IFF NOT:  Reset & Reinstall your browser + remove and power down every item on your network
    Rebuild and reboot form your first hub/router and then test.  You Should be clear !!
    THEN connect one item at a time testing each one for infection
    I DO NOT KNOW if it infects printers + scanners et al+++ but mine are OK

  • Hi, my firefox browser hacked by iclaro search engine. when i am trying to open new tab it's autometically redirected to iclaro search, please help.

    Hi,
    when i am trying to open a new tab, it's auto redirect to "isearch.claro-search.com/?affID=115131&tt=3312_5&babsrc=NT_iclro&mntrId=8aa792f7000000000000000000000000" this url, pls help me how to resolve it.

    hello runnu07, you can either install the [https://addons.mozilla.org/firefox/addon/searchreset/ search reset] addon or manually reset the new tab page by entering '''about:config''' into the firefox location bar (confirm the info message in case it shows up), searching for the preference named '''browser.newtab.url''' and right-clicking & resetting it to its default value ('''about:newtab''').

  • JScrollbar / JTextArea Help

    Hi,
    I have a JTextArea with a JScrollPane on it.
    static JTextArea data = new JTextArea(20, 60);
       static JScrollPane scroll = new JScrollPane(data, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);This works all fine on the screen.
    The only problem is that when i append data, the scroll bar will not "Automatcally" scroll.
    I have looked around the forums and looked at the API's, but cant find anything.
    Hope someone can help
    Thanks

    hmmmmm....
    this is my code... seems to work for me.... to do what i said that is... :
           private void appending(Color c, String s) { // better implementation--uses StyleContext
             StyleContext sc = StyleContext.getDefaultStyleContext();
             AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY,
                                                 StyleConstants.Foreground, c);
           pane.setCaretPosition(0);  // place caret at the top/beginning
             pane.setCharacterAttributes(aset, false);
             pane.replaceSelection(s); // there is no selection, so inserts at caret
           }then to use:
                        appending(Color.black,("Single click halts program AND exits."  + "\n" + "\n" ));

  • Redirecting stdout and stderr to GUI

    Hello,
    Is it possible to redirect System.out and System.err output to a JTextArea or a JLabel? This output will be coming from another class that is instantiated from within my GUI class.
    Any suggestions or otherwise would be appreciated,
    Thanks.

    you need to define a PrintStream for it.
    suggest you write a class extending OutputStream and in the flush() method include the writing to the text area.
    MyOutStream outStream = new MyOutStream();
    PrintStream ps = new PrintStream(outStream.getOutStream(), true);
    System.setErr(myPrintStream);
    System.setOut(myPrintStream);
    can get messy mind you.
    hope this points you in some useful direction.
    Takis

  • JTextArea help!

    Ok i have a frame, in that frame i have a JTextArea and JTextField. The JTextArea displays a document which i opened using FileReader and appeneded it. In the JTextField i need to type a query and it should highlight the matching word in the JTextArea. It doesn't need to even highlight, it just needs to show the user where it is in the JTextArea.
    I just can't seem to do this, i even tried moving the scrollbar to that position, but it don't work. Please help :(

    Try this:
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import javax.swing.*;
    public class TextAreaExample implements Runnable, ActionListener {
        JTextArea area;
        public void run() {
            area = new JTextArea(30,40);
            try {
                area.read(new FileReader("TextAreaExample.java"), null);
            } catch (IOException e) {
                e.printStackTrace();
            JTextField field = new JTextField(40);
            field.addActionListener(this);
            JFrame f = new JFrame("TextAreaExample");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(new JScrollPane(area));
            f.getContentPane().add(field, BorderLayout.SOUTH);
            f.pack();
            f.setLocationRelativeTo(null);
            f.setVisible(true);
        public void actionPerformed(ActionEvent evt) {
            String search = evt.getActionCommand();
            if (search.equals(""))
                return;
            String current = area.getSelectedText();
            int start = area.getSelectionStart();
            if (search.equals(current))
                start++;
            int next = area.getText().indexOf(search, start);
            if (next == -1)
                area.getCaret().setDot(0);
            else {
                area.getCaret().setDot(next);
                area.getCaret().moveDot(next + search.length());
                area.getCaret().setSelectionVisible(true);
        public static void main(String[] args) {
            EventQueue.invokeLater(new TextAreaExample());
    }

  • HT1689 Can't get iTunes .ipad says "too many http redirects " what's that anyone help please? been charged twice for double down chips.

    What does "Too Many HTTP redirects" please? I am trying too report a purchasing problem, but keep getting that message. I'm trying to connect too ITunes.

    Susiebwb wrote:
    Can any one please assist me.... I paid twice for an app by mistake.... ...
    To Contact iTunes Customer Service and request assistance
    Use this Link  >  Apple  Support  iTunes Store  Contact

  • (C) Redirecting stdout to a buffer

    I'm currently authoring a python binding for a third-party application. A function of the third-party applications allows users to set the filename to "-" which will then print the result to stdout. I'd like to be able to catch that output into a buffer and handle it entirely in memory rather than creating a temporary file on disk (that's why freopen does not fit for this). Can someone give me a hint?

    POSIX is fine. It may be great to have a platform-independent way for doing this, but I found my solution with glibc's open_memstream().

  • How to redirect stdout & stderr to a logfile

    Hello All,
    I'm new to java. I have to redirect all the output that get printed to a logfile (text) on my hard disk?
    Can anyone plz give me a pointer?
    thanks
    Sumanth

    He probably means this but doesnt know how to ask for it:
    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/System.html
    static void setErr(PrintStream err)
    Reassigns the "standard" error output stream.
    static void setIn(InputStream in)
    Reassigns the "standard" input stream.
    static void setOut(PrintStream out)
    Reassigns the "standard" output stream.

  • I have purchased the creative cloud  software, but when I try to download it, it redirects me to purchase it. help?

    I have purchased the creative cloud  software, but when I try to download it,it says trial expired and redirects me to purchase it.

    Are you getting Trial Expired error message while launching CC apps like Photoshop , Illustrator.,...etc?
    Or you are getting Trial Expired message under Apps menu in Creative Cloud ?
    Are you using Windows computer or Mac ?

Maybe you are looking for

  • BAPI for Creation of Inbound delivery Document

    Hi I have found a BAPI for Creating Inbound delivery Document, BBP_INB_DELIVERY_CREATE. I filled the below parameters and executed it. IS_INB_DELIVERY_HEADER          DELIV_DATE                     11.04.2007                            IT_INB_DELIVER

  • Need help about setting up a JMS sender channel

    I just started to play with PI for a few weeks and I'm trying to setup a simple JMS sender channel to read stuff from a WebSphere MQ. I've someone installed JMS adaptor for me, but we never know it is correctly installed or not. First question is "Is

  • Conversion of date to float

    Can anyone tell me how to convert the date value to float value Ex now i have a val 30-jul-2007 this i need to insert as 20070730 i.e yyyymmdd as that field data type is float or give me a function for changing the date format as we use format in sql

  • Help me... what i can do!!!

    i have a 4s. i bought it. its icloud locked. then i called my seller. he gave me a account. and i tried it. and then it says to reset account with its email. i dont know that. and when i call back my seller he is not answering and now he blocked me.

  • Help flash drive

    how do i save things on to my flash drive and how do i remove my flash drive