Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2009
    Posts
    5
    Rep Power
    0

    Default System.out.println to a jtextarea

    i have a methord which out puts to a console which i use throughout my program:

    Java Code:
        public static void println(String message) {
           System.out.println(message);
    
        }
    i am wanting to replace the system.out.println with a textarea.append(message), i have done it but the only way i could make it work if it makes a new instance of the text area frame otherwise i get a error about the static content :/ any ideas?
    thanks in advanced.

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    835
    Rep Power
    6

    Default

    Hi,
    U can do it using awt or swing.Not in normal code.U try to write something so that we can give idea.

    -Regards
    Ramya
    Ramya:cool:

  3. #3
    Join Date
    Mar 2009
    Posts
    5
    Rep Power
    0

    Default

    Java Code:
    package Bulby.util;
    
    import javax.swing.*;
    
    public class TextAreaFrame {
    
       JTextArea textArea = null;
    
       public TextAreaFrame() {
    
          JFrame frame = new JFrame();
          frame.setSize( 300 , 300 );
          frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    
          textArea = new JTextArea( 10 , 20 );
          textArea.setEditable( false );
          textArea.setLineWrap(true);
          textArea.setWrapStyleWord(true);
    
          JPanel panel = new JPanel();
          panel.add( textArea );
    
          frame.getContentPane().add( panel );
    
          frame.show();
    
       }
    
    }
    thats the code i use to call the text area but everytime i call the println methord it makes multipul instances:
    Java Code:
    public static void println(String message) {
    TextAreaFrame taf = new TextAreaFrame();
    
    taf.textArea.append( message );
    
        }

  4. #4
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    835
    Rep Power
    6

    Default

    Hi,
    You are not creating multiple objects know?.Even I tried ur code sample.It is ok only know? Please gothru this below.

    Java Code:
    import javax.swing.*;
    
     class TextAreaFrame {
    
       JTextArea textArea = null;
    
       public TextAreaFrame() {
    
          JFrame frame = new JFrame();
          frame.setSize( 300 , 300 );
          frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    
          textArea = new JTextArea( 10 , 20 );
          textArea.setEditable( false );
          textArea.setLineWrap(true);
          textArea.setWrapStyleWord(true);
    
          JPanel panel = new JPanel();
          panel.add( textArea );
    
          frame.getContentPane().add( panel );
    
          frame.show();
    
       }
    
    } 
     
    
    public class Test 
    {
      public static void main(String args[])
      {
    	TextAreaFrame taf = new TextAreaFrame();
        taf.textArea.append("Hi");
        taf.textArea.append("Example");
    
      }//main
    }//class
    Ramya:cool:

  5. #5
    Join Date
    Mar 2009
    Posts
    5
    Rep Power
    0

    Default

    thats fine if you want to call it once but i use this metord alot of times and every time it creates a new window as u can see in the image ive posted, i just want ech line to append to the same textarea
    Attached Thumbnails Attached Thumbnails System.out.println to a jtextarea-screen.jpg  

  6. #6
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    835
    Rep Power
    6

    Default

    Hi,
    The screenshots you have attached something different.It is noway related to the code portion what u have pasted.What you are trying 2 do here.Why is it telling about server and ports? Are u tring to run the same class what u have compiled.Please check it once.

    -Regards
    Ramya
    Ramya:cool:

  7. #7
    Join Date
    Mar 2009
    Posts
    5
    Rep Power
    0

    Default

    What I have posted is when the method is called it creates multiple TextAreaFrameís and that the text that is passed in to it that has nothing to do with what Iím getting at. what I want to do is insted of it making a new textAreaFrame every time the method is called just to display all the output in one textAreaFrame so insted of the last image that i posted i want it to do this:
    Attached Thumbnails Attached Thumbnails System.out.println to a jtextarea-image.jpg  

  8. #8
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    835
    Rep Power
    6

    Default

    Hi,
    1) Declare the textarea object global.
    2) instantiate the object inside main and call the println method on that object instance
    4) the println method should take the textarea argument
    5) inside println just append the data to the passed textarea object, that’s all, no more code there

    -Regards
    Ramya
    Ramya:cool:

Similar Threads

  1. System.out.println Shortcut
    By AdamCCFC in forum New To Java
    Replies: 23
    Last Post: 11-13-2011, 03:45 PM
  2. difference between system.out.println() & out.println()
    By wickedrahul9 in forum Advanced Java
    Replies: 5
    Last Post: 10-18-2008, 11:06 PM
  3. System.out.println
    By Sniper-X in forum Advanced Java
    Replies: 10
    Last Post: 05-05-2008, 03:41 PM
  4. System.out.println
    By sunjavaboy in forum Advanced Java
    Replies: 3
    Last Post: 03-22-2008, 01:30 AM
  5. Help me with system.out.println
    By baltimore in forum New To Java
    Replies: 1
    Last Post: 07-31-2007, 08:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •