GUI - Displaying system.out

Hello
I am creating a database application in Java. When an user enters an invalid query several of my class-methods call the System.out.println method. I was wondering if there was an easy way of redirecting all these print statements to a JTextArea in my JFrame(GUI)-to act like a small debug window :s
Any suggestions would be greatly appreciated

I answered something like this before
try here: http://forum.java.sun.com/thread.jsp?forum=31&thread=403289&message=1762839#1762839
Basically what you have to do is:public class JTextAreaWriter extends Writer
  protected JTextArea writeTo;
  public JTextAreaWriter(JTextArea writeTo)
    if (writeTo == null) throw new NullPointerException();
    this.writeTo = writeTo;
  public void close() {}
  public void flush() {}
  public void write(char[] cbuf)
    writeTo.append(new String(cbuf));
  public void write(char[] cbuf, int off, int len)
    writeTo.append(new String(cbuf, off, len));
  public void write(int c)
    writeTo.append((char)c + "");
  public void write(String str)
    writeTo.append(str);
  public void write(String str, int ofs, int len)
    writeTo.append(str.substring(ofs, ofs + len));
System.setOut(new PrintWriter(new JTextAreaWriter(myJTextArea)));You can also use System.setErr in the same way, with a different JTextArea
HTH
=====
Phlip

Similar Messages

  • System.out console in GUI

    hi i'm constructing a GUI for one of my programs using the swing librarys however i cant figure out how to display the system.out's. I really have no idea how to do it or i would post how im trying to or usual if anyone knows a better way to print strings (an undetermined number of strings this is) to a GUI please let me know

    Hi,
    Why are you using System.out combined with Swing? Just print text to some text component instead (e.g. JTextArea, see the javadoc for that class for more info)
    Kaj

  • How to get System.out msg displayed in logs

    Running SJSWSEE6.1 SP5 on Solaris
    How do I get the System.out.println messages to display in the Web Server 6.1 error/access log??
    Thanks..

    Hi,
    In your server.xml, check that the properties 'logstderr' and 'logstdout' are set to 'true'. The messages will then appear in the errors log file.
    <LOG file="<path to errors file>" loglevel="info" logtoconsole="true"
    usesyslog="false" createconsole="false" logstderr="true" logstdout="true" logvsid="false"/>
    Also, see docs at http://docs.sun.com/source/817-6248/crsrvrx.html
    Hope this helps.

  • System.out.println in gui--- question

    Hello People.
    First of all, I'm new to the forums, so if it doesn't belong here, plese tell me where to post questions like this.
    The Problem:
    I have a GUI and another class,which contains the Program.
    Here's the code of my class:
    int Battle(String CharName) {
              System.out.println(CharName + " Is fighting agains a monster");
              while (CharHP > 0 && MonsterHP != 0) {
                   MonsterHP = MonsterHP - CharDmg;
                   System.out.println("The monster has " + MonsterHP + "Hitpoints left ");
                   CharHP = CharHP - MonsterDamage;
                   System.out.println(CharName + " has " + CharHP + " Hitpoints left");
              if (MonsterHP == 0) {
                   System.out.println(CharName + "Has lost the fight!");
                   CharEXP = CharEXP + 20;
                   System.out.println("You have gained " + CharEXP + " Exp");
              if (CharHP == 0) {
                   System.out.println("You have lost the fight!");
              return CharHP;
         }So what would be the code to print all the "System.out.println's" here into the gui test area?

    camickr wrote:
    Check out the [Message Console|http://www.camick.com/java/blog.html?name=message-console].
    Just out of curiosity, how do you come up with ideas for all the awesome stuff on your blog?

  • How to display double byte characters with system.out.print?

    Hi, I'm a newbie java programmer having trouble to utilize java locale with system io on dos console mode.
    Platform is winxp, jvm1.5,
    File structure is:
    C:\myProg <-root
    C:\myProg\test <-package
    C:\myProg\test\Run.java
    C:\myProg\test\MessageBundle.properties <- default properties
    C:\myProg\test\MessageBundle_zh_HK.properties <- localed properties (written in notepad and save as Unicode, window notepad contains BOM)
    inside MessageBundle.properties:
    test = Hello
    inside Message_zh_HK.properties:
    test = &#21890; //hello in big5 encoding
    run.java:
    package test;
    import java.util.*;
    public class Run{
      public static void main(String[] args){
        Locale locale = new Locale("zh","HK");
        ResourceBundle resource =
            ResourceBundle.getbundle("test.MessageBundle", locale);
        System.out.println(resource.getString("test"));
      }//main
    }//classwhen run this program, it'll kept diplay "hello" instead of the encoded character...
    then when i try run the native2ascii tool against MessageBundle_zh_HK.properties, it starts to display monster characters instead.
    Trying to figure out what I did wrong and how to display double byte characters on console.
    Thank you.
    p.s: while googling, some said dos can only can display ASCII. To demonstrate the dos console is capable of displaying double byte characters, i wrote another helloWorld in chinese using notepad with C# and compile using "csc hello.cs", sure enough, console.write in c# allowed me to display the character I was expecting. Since dos console can print double byte characters, I must be missing something important in this java program.

    after google a brunch, I learned that javac (hence java.exe) does not support BOM (byte order mark).
    I had to use a diff editor to save my text file as unicode without BOM in order for native2ascii to convert into a ascii file.
    Even the property file is in ascii format, I'm still having trouble to display those character in dos console. In fact, I just noticed I can use system.out.println to display double byte character if I embedded the character itself in java source file:
    public class Run {
         public static void main(String[] args) throws UnsupportedEncodingException{
              String msg = "&#20013;&#25991;";    //double byte character
                    try{
                    System.out.println(new String(msg.getBytes("UTF-8")) + " new string");  //this displays fine
                    catch(Exception e){}
                    Locale locale = new Locale("zh", "HK");
              ResourceBundle resource = ResourceBundle.getBundle("test.MessagesBundle", locale);
                    System.out.println(resource.getString("Hey"));      //this will display weird characterso it seems like to me that I must did something wrong in the process of creating properties file from unicode text file...

  • Getting System.out statements to be displayed in a text field

    Hi,
    I'm trying to direct the system.out.println stream to a text field in Swing so that when any system.out.println statemetns are executed the text field will display them as well. I would imagine there has to be some kind of event listener. Any ideas?

    look here

  • How to open the server log file that displays messages of System.out.print

    Hi,
    I am working on a j2ee project. How can we access the default log file? I have put many System.out.println(..) method in different classes in order to get the program flow and to track the origin of the error.
    I opened the a log file named "defaultTrace.0.trc" in usr\sap\J2E\JC00\j2ee\cluster\server0\log installation directory. Although it shows the ecxeptions, It is not showing the messages that i have written to console with the help of System.out.println(..) method.
    Can anybody tell me the location of the log file where i can find my messages sent through System.out.println(..) function?
    Regards,
    Sudheesh...

    System.out.println goes to console, which is not a file... This whole thing is much easier if you use standard logging:
    http://help.sap.com/saphelp_nw04/helpdata/en/d2/5c830ca67fd842b2e87b0c341c64cd/frameset.htm

  • Help: What can make "System.out.println" not displaying anything?

    Hello,
    We have Portal 10g.
    I have noticed a pb on the interpretation of existing JSP pages.
    I simplified the code... and I noticed that even this command doesn't work :
    <%
    System.out.println("Hello World");
    %>
    Any idea ?
    Is there any security ? permission I should get ?
    JSP works fine on our old 8i environment ...
    Thanks in advance for your help.
    Olivier

    Olivier,
    between 8i and 10g are aeons of time (for computer technology). As far as I recall, in 8i came with a Apache and JServ module. This supported Servlets and JSP through a special Oracle implementation. After that OC4J as a J2EE container for EJBs and Servlets/JSPs was introduced.
    Using JSPs with the database installation only is not advised anymore. You can use OC4J for that. But be aware that will require some changes in the configuration and deployment of JSPs.
    HTH,
    --olaf                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • System out on Dual Monitor systems

    Hi,
    I am trying to write an application running on single processor, but dual monitor facility. So differnet monitor must get differnet display from same process.
    May I know how can I capture the monitor standard output. I know we have System.out that is set to standard monitor, in this case I "think" it will consider the first monitor has standard output. So, how can I capture actual output stream to each monitor so that I can set the system out property to which ever monitor I wish.
    Thanks
    HKG...

    I don't understand. System.out and System.err write to the standard out and err streams. When running Java in a command window under a GUI environment like Windows, Mac OS or Unix or Linux with X-based graphical displays, these streams will be default be displayed in the shell window that started the program. This window will be on what every display you placed it, the Java program has no control.
    If the Java program is a GUI (AWT, Swing or SWT), then System.out and System.err output still goes (by default) to whatever shell window started the program or into the bit bucket if no shell windows as associated with starting the program.

  • System.out broke?

    I'm programming in linux and I've made a simple program that run's a GUI display. I added a menu item action listener and inside the action method it should print something or anything it doesn't matter. My only problem is that it never prints. Furthermore, I put a System.out before the System.exit in the File | Exit menu and it skips over that and exits the program with no output. When I put System.out's in the public static void main method it works fine, after the GUI starts, nothing prints. Any ideas?

    I'm programming in linux and I've made a simple
    program that run's a GUI display. I added a menu
    item action listener and inside the action method it
    should print something or anything it doesn't matter.
    My only problem is that it never prints.
    . Furthermore, I put a System.out before the
    System.exit in the File | Exit menu and it skips over
    that and exits the program with no output. When I
    put System.out's in the public static void main
    method it works fine, after the GUI starts, nothing
    prints. Any ideas?My experience in linux is limited, with none of it being in Java. However, long ago, printing in Unix from C, output got buffered until the OS decided it was ready to print. You could force it by doing a fflush.
    You can also do a flush in Java. Try:
    System.out.println( "OUTPUT HERE" );
    System.out.flush();and see if that forces the output.
    Good luck.
    World spins
    RD-R
    � {�                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Is there a way to force System.out.println to run when called

    I working on my first threaded program and having a hard time debugging. I've used System.out.println to let me know what's going on but due (I assume) to the nature of threads the output is not sequential. Is there a way to force println to execute immediatly so that they show up in the order they were called?
    Thanks --- Mike

    mjs1138 wrote:
    endasil, Thanks for the reply. I'm currenlty running the program from within the NetBeans IDE. It is the output displayed by in NetBeans "output" that I'm looking at.
    --- MikeI don't use Netbeans, but I would guess that it too pipes Standard Out and Standard Error to the same console. You didn't address my comment. Are you printing to System.err as well? This happens implicitly if you use Exception.printStackTrace(), for example.

  • 27 inch thunderbolt display blacks out after Thunderbolt Firmware Update 1.2

    Bought 2 new 27 inch TB displays for two different machines and after a couple of days the Thunderbolt Firmware Update 1.2 appears on my Mac Pro with one of the displays installed. So I install the firmware update.  Now my display blacks out periodically and I keep getting Graphic Display Errors with a request to sent the errors to Apple. Running a 32 GB Mac Pro (late 2013 circular style) I have three monitors connected (two 20 inch cinema displays and the new 27 inch display). This machine is supposed to be able to handle three 4k monitors or 6 standard TB displays.  I've seen the posts about the blacking out with this monitor but I didn't have any problems before the firmware update and now I've got them pretty regularly.  I had the blacking out problem on an earlier monitor and took one of the monitors back and Apple gave me another one and this is the replacement.  Same problem, but this one only started after the update. I'm hoping someone from Apple reads these messages and can let me know what's up.
    BTW, I also have an older 27 inch Apple monitor that ran perfectly on this machine so I'm disappointed that I spent all this money and now get the blacking out issue.
    Mac Pro (Late 2013)
    Processor 3.7 GHz Quad-Core Intel Xeon E5
    Memory 32 BG
    Graphics AMD FirePro D300 2048 MB

    I have my Thunderbolt display connected to my MacBook Pro and have been experiencing the same issue, getting worse over time.  The folks at my local Apple store did not know what to do about it.  So, I looked around and tried different thing.
    The one thing that seems to be working is to System Preferences > Build-in Display > uncheck “Automatically adjust brightness.”
    I hope this helps.

  • How to capture System.out, done by another program

    Hi All,
    My application runs other application in back. How can I capture system.out.println() written by another application & display via dialog box.
    Like :execl() or execv() function in C runtime library. Where every printf() message printed to passed buffer.
    Thank you,
    Avin Patel

    You can create an InputStream from a started process. Then read all the bytes from the inputstream and write them to an outputstream (like System.out)
    Process p = Runtime.getRuntime().exec(COMMAND);
    InputStream is = p.getErrorStream();   //Or another stream
    int[] buffer = new int[128];
    while((read = is.read(buffer)) != -1){
    System.write.out(buffer, 0, read);
    }

  • Large file read in, system out error!

    the following method simply reads 6MB text file by each line.
    After reading a line, separate the line with '\t', and obtain 2 tokens.
    After getting 2 tokens, synthesis the 2 tokens into another string token.
    Sythesized token is displayed with System.out.println().
    However, I can't have all contents from the input file, and I can't dispaly all of them in monitor screen, either.
    What's wrong with my code?
    PS: each line of the input file is structured by "key\tcontent\n" , and the number of lines is 400000.
    ===========
    public void makeDictionary(){
    String line;
    try{
    BufferedReader in = new BufferedReader( new FileReader(filePath));
    while( (line = in.readLine()) != null ){
    String key;
    String content;
    int index = line.indexOf('\t');
    key = line.substring(0, index);
    content = line.substring(index+1, line.length());
    System.out.println( key + "\t" + content );
    System.out.flush();
    in.close();
    catch( Exception e){}
    }

    Thank you for your answer.
    I can't enough thank you.
    Actually, I used try..catch structure for my code, however I didn't get any message from catch block. In addition to this, the process didn't stop; in other word, the process was going on while doing nothing. I monitored the utilizaton of CPU and memory. The utilization of CPU was 100%, but after a while, it was 0%, even though process was still alive. The state which the process was doing nothing continued forever.
    Frankly speaking, I used this code for constructing my own data structure from a large text file. While debugging my code, I realized that the method, readLine() of BufferedReader class didn't load all the data of the input file, so I made the code for testing.
    Anyway, I am just fully depending on your answer. Please help me!!!!
    Your quick response will be appreciated.

  • Strange System.out.print behavior inside a for loop

    I'm trying to create a simple ASCII progress bar in the console that would display like this:
    |--------------------------------------------|
    ============================More equal signs would appear as time goes on. At least this is what I want to happen.
    Instead, what happens is, none of the equal signs are printed until the very end, after the for loop in which the System.out.print("=") statement is in, has exited.
    This is my code (probably more than necessary is shown, but the important part is the for loop):
        public void addSomeDiffys(int numOfDiffys, int minInt, int maxInt) {
            Diffy currentDiffy;
            System.out.println("\nCreating Diffys.");
            System.out.println("|--------------------------------------------|");
            for (int i=0; i < numOfDiffys; i++) {
                currentDiffy = new Diffy(minInt, maxInt);
                if ((i/(double)numOfDiffys)*100 % 2 == 0)
                    System.out.print("=");
                diffyList.add(currentDiffy);           
            System.out.println("\n" + diffyList.size() + " Diffys created.\n");
            System.out.println("Sorting according to highest rating...");
            Collections.sort(diffyList,Diffy.HIGHEST_RATING_ORDER);
            System.out.println("Done.\n");
        }I also tried changing the System.out.print("="); to System.out.println("="); This time it works as expected, its just not very pretty...
    I get something like this:
    |--------------------------------------------|
    =
    =
    =
    =
    =
    =
    =
    =
    =
    =
    =
    =So again, when I use println, rather than print, the equal signs are printed over time, slowly, as the progress increases. When using print, Nothing happens for a long time, and then suddenly they all appear after the for loop has terminated, which makes no sense.
    Thanks for any help.

    When using print, Nothing happens
    for a long time, and then suddenly they all appear
    after the for loop has terminated, which makes no
    sense.
    Yes it does make sense! The characters are buffered inside the PrintStream and written when there is a full line to write. You could try a flush() after each = is written but I have no confidence that it will make any difference.

Maybe you are looking for