Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 2 12 LastLast
Results 1 to 25 of 32

Thread: Java GUI Problem, I am having trouble getting my TextArea to resemble console output.

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java GUI Problem, I am having trouble getting my TextArea to resemble console output.

    I am having trouble getting my GUI TEXTAREA field to resemble my console output. The GUI contains a short explanation of what I am looking for. I have tried converting the integer array to a string array but the output is not the same as the command line. Can someone explain what I am doing wrong.

    import java.io.FileReader;
    import java.io.PrintWriter;
    import java.util.Arrays;
    import java.util.Scanner;
     
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
     
     
    public class RecurringGrowthCell 
    {
     
     
    	public static void main(String[] args)
    	{
    		 String textArea1 = "Hello can someone help me, I want to replace the text in this field with \nthe data that you see in the command line.\n"
    				 + "I am monitoring bacterial growth in our science lab at work, and keeping track of each recurring growth number by paper is quite difficult\n"
    				 + " since papers tend to get easily misplaced in the lab.\n" + "I would like to have the same output from the command line placed in a GUI textArea, " 
    				 + "preferably this textArea." + " Can someone tell me what should I do first or point out what I am doing wrong." + "\n\n\n\n\n\n\n Thanks";
    		//Set JTextArea text to created String
    		JTextArea textArea = new JTextArea(textArea1); 
    		//Set JTextArea to line wrap
    		textArea.setLineWrap(true); 
    		//Set JTextArea text to word wrap
    		textArea.setWrapStyleWord(true);
    		//Create scrollbar for text area
    		JScrollPane scrollBarForTextArea=new JScrollPane(textArea,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);  
    		JFrame frame=new JFrame("Recurring Growth Data");  
    		frame.add(scrollBarForTextArea);  
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     
    		frame.setSize(500,500);
    		frame.setLocationRelativeTo(null);  
    		frame.setVisible(true);
     
    		Growth_Numbers();
    	}
     
    	private static void Growth_Numbers() 
    	{
    		 try {
    			 	//Open file to read
    		        BufferedReader reader1 = new BufferedReader(new FileReader("col1.csv"));
    		        //========================================================================================
    		        int[] Growth_numbers1 = new int[73];
    		        //========================================================================================
    		        //Initialize all counts to zero.
    		        for (int i = 0; i < 73; i++ )			//Growth column
    		        {Growth_numbers1[i] = 0;}
    		        //========================================================================================
    		        String Growth_nums;
    		        //========================================================================================
    		        //========================================================================================
    		        while ((Growth_nums = reader1.readLine()) != null) 
    		        {
    		            String[] pieces1 = Growth_nums.split(",");
     
    		            for (int j = 1; j <= 1; j++) 
    		            {
    		                int IncrementNumber1 = Integer.parseInt(pieces1[j]);
    		                Growth_numbers1[IncrementNumber1]++;
    		            }
    		        }
    		        reader1.close();
    		        //=========================================================================================
    		        //=========================================================================================
    		        // Loop through array of counts to print them and their frequency.
    		        for (int i = 1; i < 73; i++) 
    		        {
    		            show_text(i, Growth_numbers1);
    		        }
    		       //Nums = Arrays.toString(Growthnumbers1);
    		       //System.out.println(Nums);
     
    		    } 
    		 	catch (Exception e) 
    		    {
    		        System.out.println("There was a problem opening and processing the file.");
    		    }
     
     
    	}
     
    	//show_text ===================================================================================
    	public static int[] show_text(int i, int[] Growth_numbers1) 
    	{	
    		System.out.printf("%-10s\n", new Object[]{ i + ": " + Growth_numbers1[i] });
    		return Growth_numbers1;
    	}
     
     
    }


    I have made multiple attempts to get my GUI TEXTAREA output to resemble my console output. I don't know what I am doing wrong. I was successful in one attempt at getting the following output to my TEXTAREA.

    [ 0, 0, 6, 10, 4, 4, 7
    2, 4, 6, 5, 3, 1, 4, 4
    3, 0, 2, 5, 2, 0, 0, 0,
    2, etc, etc, etc, ]

    The above output is what I got in my GUI. This is the "output" that I do not want.
    The output below is what I would like to see in my GUI TEXTAREA.

    1: 6
    2: 10
    3: 4
    4: 4
    5: 7
    6: 2
    7: 4
    8: 6
    9: 4
    10: 5
    11: 3
    12: 1
    13: 4
    14: 4
    15: 3
    16: 0
    17: 2
    18: 5
    19: 2
    20: 0
    21: 0
    22: 0
    23: 2
    24: 3
    25: 1
    26: 0
    27: 0
    28: 3
    29: 0
    30: 0
    31: 0
    32: 0
    33: 0
    34: 1
    35: 0
    36: 1
    37: 0
    38: 0
    39: 0
    40: 0
    41: 0
    42: 0
    43: 0
    44: 0
    45: 0
    46: 0
    47: 0
    48: 0
    49: 0
    50: 0
    51: 0
    52: 0
    53: 0
    54: 0
    55: 0
    56: 0
    57: 0
    58: 0
    59: 0
    60: 0
    61: 0
    62: 0
    63: 0
    64: 0
    65: 0
    66: 0
    67: 0
    68: 0
    69: 0
    70: 0
    71: 0
    72: 0
    =======================================

    Can someone tell, show, explain, comment, offer an opinion, advice, etc, on what my first step should be?


    I have uploaded the col.txt file that the code reads. Feel free to run the code to get a general idea of what I should do.
    I have uploaded the code and output for those who would like to run the code to see what the problem is. You do not have to run it, you do not have to solve it if you don't
    want to. I would appreciate advice on what I'm doing wrong or where I should start.



    Thanks
    Attached Files Attached Files


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Java GUI Problem, I am having trouble getting my TextArea to resemble console output.

    Text can be added to a JTextArea using the append() method. Using that, you should be able to write the the JTextArea so that the output is similar to what you see on the console.

  3. #3
    Junior Member
    Join Date
    Sep 2014
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java GUI Problem, I am having trouble getting my TextArea to resemble console output.

    Thanks, Im not too familiar with its capabilities but I will look into it and get back with my revised code and some info on wether or not I was succcessful with using the append function.

  4. #4
    Junior Member
    Join Date
    Sep 2014
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java GUI Problem, I am having trouble getting my TextArea to resemble console output.

    Ok, so I have restarted my GUI application from scratch. I have tried using the "append" or "append toString" method and it did not quite work for me. I just couldn't figure it out.
    So, I have redid my code and below is the code I have so far. I was finally able to get my GUI to read the file but it still does not resemble my console output.

    Can someone please help?


    import java.io.*;
    import java.util.Arrays;
    import java.io.FileReader;
    import java.io.PrintWriter;
    import java.util.Arrays;
     
    import javax.swing.*;
     
    public class RecurringGrowthCells
    {
     
        public static void main(String[] args)
        {
     
            JFrame frame = new JFrame("Recurring Bacterial Growth Data");
            JTextArea textArea = new JTextArea();
            int[] Growth_numbers1 = new int[73];
     
            String text = "";
     
            try{
     
                BufferedReader reader1 = new BufferedReader(new FileReader("col1.csv"));
     
                for (int i = 0; i < 73; i++ )			//Growth
    	        {Growth_numbers1[i] = 0;}
     
                String Growth_nums = "";
     
                while(Growth_nums!=null)
                {
                	Growth_nums = reader1.readLine();
                    String[] pieces1 = Growth_nums.split(",");
     
                    for (int j = 1; j <= 1; j++) 
    	            {
    	                int IncrementNumber1 = Integer.parseInt(pieces1[j]);
    	                Growth_numbers1[IncrementNumber1]++;
    	            }
                    //Arrays.sort(Growth_numbers1);
                    //String[] a=Arrays.toString(Growth_numbers1).split("[\\[\\]]")[1].split(", "); 
                    //System.out.println(Arrays.toString(a)); 
                    //text = text + Growth_nums + Growth_numbers1 + a +  Arrays.toString(a) + "\n";
                    text = text + Growth_nums + Growth_numbers1 + "\n";
     
     
                    //For Loop is for console output.... Not GUI
                    for (int i = 1; i < 73; i++) 
        	        {
        	            show_text(i, Growth_numbers1);
        	        }
        	       //Nums = Arrays.toString(Growthnumbers1);
        	       //System.out.println(Nums);
                }
     
            }catch(Exception ex){
                ex.printStackTrace();
                System.out.println("Why is this exception being thrown.");
            }
     
            textArea.setText(text);
     
            frame.add(new JScrollPane(textArea));
            frame.setSize(500, 800);
            frame.setLocationRelativeTo(null);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
        }
     
        //show_text ===================================================================================
      	public static int[] show_text(int i, int[] Growth_numbers1) 
      	{	
      		System.out.printf("%-10s\n", new Object[]{ i + ": " + Growth_numbers1[i] });
      		return Growth_numbers1;
      	}
    }

    This is my GUI output:
    ================================================== ======================================
    9/17/14,18[I@237dc815
    9/17/14,18[I@237dc815
    9/17/14,18[I@237dc815
    9/17/14,18[I@237dc815
    9/17/14,18[I@237dc815
    9/13/14,1[I@237dc815
    9/10/14,2[I@237dc815
    9/6/14,9[I@237dc815
    9/3/14,2[I@237dc815
    8/30/14,5[I@237dc815
    8/27/14,17[I@237dc815
    8/23/14,28[I@237dc815
    8/20/14,4[I@237dc815
    8/16/14,7[I@237dc815
    8/13/14,8[I@237dc815
    8/9/14,3[I@237dc815
    8/6/14,1[I@237dc815
    8/2/14,12[I@237dc815
    7/30/14,13[I@237dc815
    7/26/14,24[I@237dc815
    7/23/14,4[I@237dc815
    7/19/14,10[I@237dc815
    7/16/14,5[I@237dc815
    7/12/14,2[I@237dc815
    7/9/14,9[I@237dc815
    7/5/14,24[I@237dc815
    7/2/14,8[I@237dc815
    6/25/14,10[I@237dc815
    6/21/14,5[I@237dc815
    6/18/14,6[I@237dc815
    6/14/14,9[I@237dc815
    6/11/14,14[I@237dc815
    6/7/14,28[I@237dc815
    6/4/14,1[I@237dc815
    5/31/14,15[I@237dc815
    5/28/14,2[I@237dc815
    5/24/14,15[I@237dc815
    5/21/14,4[I@237dc815
    5/17/14,23[I@237dc815
    5/14/14,7[I@237dc815
    5/10/14,4[I@237dc815
    5/7/14,17[I@237dc815
    5/3/14,5[I@237dc815
    4/30/14,2[I@237dc815
    4/26/14,3[I@237dc815
    4/23/14,19[I@237dc815
    4/19/14,5[I@237dc815
    4/16/14,34[I@237dc815
    4/12/14,14[I@237dc815
    4/9/14,9[I@237dc815
    4/5/14,11[I@237dc815
    4/2/14,8[I@237dc815
    3/29/14,2[I@237dc815
    3/26/14,28[I@237dc815
    3/22/14,13[I@237dc815
    3/19/14,2[I@237dc815
    3/15/14,2[I@237dc815
    3/12/14,14[I@237dc815
    3/8/14,10[I@237dc815
    3/5/14,3[I@237dc815
    3/1/14,3[I@237dc815
    2/26/14,11[I@237dc815
    2/22/14,2[I@237dc815
    2/19/14,1[I@237dc815
    2/15/14,2[I@237dc815
    2/12/14,36[I@237dc815
    2/8/14,24[I@237dc815
    2/5/14,8[I@237dc815
    2/1/14,5[I@237dc815
    1/29/14,11[I@237dc815
    1/25/14,8[I@237dc815
    1/22/14,1[I@237dc815
    1/18/14,13[I@237dc815
    1/15/14,7[I@237dc815
    1/11/14,10[I@237dc815
    1/8/14,10[I@237dc815
    1/4/14,19[I@237dc815
    1/1/14,15[I@237dc815
    12/28/13,8[I@237dc815
    12/25/13,23[I@237dc815
    12/21/13,25[I@237dc815
    12/18/13,7[I@237dc815
    12/14/13,14[I@237dc815
    12/11/13,1[I@237dc815
    12/7/13,13[I@237dc815
    12/4/13,6[I@237dc815
    11/30/13,5[I@237dc815
    ================================================== ==========================

    What I would like to see in my GUI output is the output below:
    ================================================== ==========================
    1: 6
    2: 10
    3: 4
    4: 4
    5: 7
    6: 2
    7: 4
    8: 6
    9: 4
    10: 5
    11: 3
    12: 1
    13: 4
    14: 4
    15: 3
    16: 0
    17: 2
    18: 5
    19: 2
    20: 0
    21: 0
    22: 0
    23: 2
    24: 3
    25: 1
    26: 0
    27: 0
    28: 3
    29: 0
    30: 0
    31: 0
    32: 0
    33: 0
    34: 1
    35: 0
    36: 1
    37: 0
    38: 0
    39: 0
    40: 0
    41: 0
    42: 0
    43: 0
    44: 0
    45: 0
    46: 0
    47: 0
    48: 0
    49: 0
    50: 0
    51: 0
    52: 0
    53: 0
    54: 0
    55: 0
    56: 0
    57: 0
    58: 0
    59: 0
    60: 0
    61: 0
    62: 0
    63: 0
    64: 0
    65: 0
    66: 0
    67: 0
    68: 0
    69: 0
    70: 0
    71: 0
    72: 0
    ================================================== ====================


    Help please?


    Thanks.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Java GUI Problem, I am having trouble getting my TextArea to resemble console output.

    [I@237dc815
    That String is what is returned by the toString() method for an int array.
    If you want to see the contents of the array, use the Arrays class's toString() method to format the array: System.out.println("an ID "+ java.util.Arrays.toString(theArrayName));
    If you want to see the contents of a single element in the array, use an index: theArray[theIndex]

    Where did the formatted date come from?
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    Sep 2014
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java GUI Problem, I am having trouble getting my TextArea to resemble console output.

    Where did the formatted date come from?

    It came from the col1.txt file from the original post. I forgot to post the col1.txt file in the last post, but I'll attach it in this post.


    System.out.println("an ID "+ java.util.Arrays.toString(theArrayName)); <=== I'm confused as to how this would print to a GUI. so, Basically how do I use this in my code?
    Attached Files Attached Files

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Java GUI Problem, I am having trouble getting my TextArea to resemble console output.

    If the desired output is this:
    1: 6
    2: 10
    etc

    I assume the number before the : is a line number and the number after the : is the data being read from the file.

    To have that put into the textarea you would append these 4 things:
    the linenumber
    the ": " String
    the data
    a new line character

    I have no idea why the code is doing what it is doing.

    The Arrays class's toString() method returns a String that can be used as needed. My example just printed it to the console. It could be used anywhere a String is used, like appended to a textarea.
    If you don't understand my answer, don't ignore it, ask a question.

  8. #8
    Junior Member
    Join Date
    Sep 2014
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java GUI Problem, I am having trouble getting my TextArea to resemble console output.

    The number before the : is a line number and the number after the : is number of times that growth has repeatedly occurred for that test.

    so for test 1: bacterial growth occurred 6 times.
    for test 2: bacterial growth occurred 10 times.
    and so on.

    so the file is read, and broken down to the results of growth for each test is counted. So the left side is the test number and the right side is the number of times the growth has occurred for that test.

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Java GUI Problem, I am having trouble getting my TextArea to resemble console output.

    Ok, so the data needs to be read and the counts for each test accumulated before the report is generated.

    The first step is to make the counts.
    when that works
    then print out the results
    If you don't understand my answer, don't ignore it, ask a question.

  10. #10
    Junior Member
    Join Date
    Sep 2014
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java GUI Problem, I am having trouble getting my TextArea to resemble console output.

    Yup, thats pretty much it. I have the code that makes the counts and now I just need it to print the results to the GUI exactly how it is.

    That last part "then print out the results" is pretty much where I am stuck at.

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Java GUI Problem, I am having trouble getting my TextArea to resemble console output.

    Where are the results? The code should use a simple loop that appends the 4 things I listed in post#7. The data item would be the next value from where the results are stored.
    If you don't understand my answer, don't ignore it, ask a question.

  12. #12
    Junior Member
    Join Date
    Sep 2014
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java GUI Problem, I am having trouble getting my TextArea to resemble console output.

    Sorry, I'm still confused. I'm more of a visual person. I can't understand what exactly you are trying to get me to do. Looking at my code, I see that the following section below pretty much breaks down your first 3 requests.
    for (int i = 0; i < 73; i++ )			
    	        {Growth_numbers1[i] = 0;}
     
                String Growth_nums = "";
     
                while(Growth_nums!=null)
                {
                	Growth_nums = reader1.readLine();
                    String[] pieces1 = Growth_nums.split(",");
     
                    for (int j = 1; j <= 1; j++) 
    	            {
    	                int IncrementNumber1 = Integer.parseInt(pieces1[j]);
    	                Growth_numbers1[IncrementNumber1]++;
    	            }
                    //Arrays.sort(Growth_numbers1);
                    //String[] a=Arrays.toString(Growth_numbers1).split("[\\[\\]]")[1].split(", "); 
                    //System.out.println(Arrays.toString(a)); 
                    //text = text + Growth_nums + Growth_numbers1 + a +  Arrays.toString(a) + "\n";
                    text = text + Growth_nums + Growth_numbers1 + "\n";
     
     
                    //For Loop is for console output.... Not GUI
                    for (int i = 1; i < 73; i++) 
        	        {
        	            show_text(i, Growth_numbers1);
        	        }
        	       //Nums = Arrays.toString(Growthnumbers1);
        	       //System.out.println(Nums);
                }

  13. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Java GUI Problem, I am having trouble getting my TextArea to resemble console output.

    Have you visually verified that the computed results are correct? Add a println() statement that prints out the computed results. For example if the results are in an array:
    System.out.println("the results= "+ java.util.Arrays.toString(theNameOfTheArrayWithThe Results));

    When the results look ok,
    THEN work on putting them into the textarea.
    If you don't understand my answer, don't ignore it, ask a question.

  14. #14
    Junior Member
    Join Date
    Sep 2014
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java GUI Problem, I am having trouble getting my TextArea to resemble console output.

    This is what I got in my console output when I inserted your System.out.println statement.

    the results= [0, 6, 10, 4, 4, 7, 2, 4, 6, 4, 5, 3, 1, 4, 4, 3, 0, 2, 5, 2, 0, 0, 0, 2, 3, 1, 0, 0, 3, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

    It prints out the recurring results but not the test number..

  15. #15
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Java GUI Problem, I am having trouble getting my TextArea to resemble console output.

    That output is for debugging so you can visually check the results.
    Do the results look ok?
    If so, that println() can be commented out of the code.

    If the results are good, use the 4 steps I mentioned in post#7 inside a loop to build the textarea display.
    I assume the position of the number in the array corresponds to the test number to be printed.
    If you don't understand my answer, don't ignore it, ask a question.

  16. #16
    Junior Member
    Join Date
    Sep 2014
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java GUI Problem, I am having trouble getting my TextArea to resemble console output.

    The array is perfect, your system println confirmed it. It confirms how many times the test occurred.

    I will work on the steps and get back to you in a bit.

    --- Update ---

    So, this is the change I made. It prints out the array in my GUI textArea.

    textArea.setText(text);
    textArea.setText(java.util.Arrays.toString(Growth_ numbers1).trim()); <======= change made here. Your print statement.
    textArea.setLineWrap(true);
    frame.add(new JScrollPane(textArea));

    This is what gets printed.
    [0, 6, 10, 4, 4, 7, 2, 4, 6, 4, 5, 3, 1, 4, 4, 3, 0, 2, 5, 2, 0, 0, 0, 2, 3, 1, 0, 0, 3, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

    So, I guess I am stuck on getting this is column form. Are there any suggestions or tutorials that you might recommend in putting the array in column form with each test number listed along side?

    1: 6
    2: 10
    3: 4
    4: 4
    5: 7

  17. #17
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Java GUI Problem, I am having trouble getting my TextArea to resemble console output.

    can you post the code that does the 4 steps shown in post#7
    Those steps should produce this:
    1: 6
    2: 10
    3: 4
    4: 4
    5: 7
    If you don't understand my answer, don't ignore it, ask a question.

  18. #18
    Junior Member
    Join Date
    Sep 2014
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java GUI Problem, I am having trouble getting my TextArea to resemble console output.

    System.out.println("the results= "+ java.util.Arrays.toString(Growth_numbers1));
    text = text + java.util.Arrays.toString(Growth_numbers1);
    textArea.append(Growth_nums + "\n");

    --- Update ---

    I tried this also, no luck...

    text = text + Growth_nums + Growth_numbers1 + "\n";
    text = "1" + Growth_numbers1 + System.getProperty((","));

  19. #19
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Java GUI Problem, I am having trouble getting my TextArea to resemble console output.

    What you posted does not use the 4 steps.
    The 4 steps in post #7 need to be inside of a loop that gets the data items one at a time from the array.


    Do you know how to access the elements in an array? The code in post#1 has several places it accesses elements of an array, so I assumed you know how to do it.
    If you don't understand my answer, don't ignore it, ask a question.

  20. #20
    Junior Member
    Join Date
    Sep 2014
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java GUI Problem, I am having trouble getting my TextArea to resemble console output.

    ok, so I have made some changes and now it prints the array in column form but with a bunch of zeros.

     
                while(Growth_nums!=null)
                {
                	Growth_nums = reader1.readLine();
                    String[] pieces1 = Growth_nums.split(",");
     
     
                    for (int j = 1; j <= 1; j++) 
    	            {
    	                int IncrementNumber1 = Integer.parseInt(pieces1[j]);
    	                Growth_numbers1[IncrementNumber1]++;
    	            }
                    Arrays.sort(Growth_numbers1);
                    //String[] a=Arrays.toString(Growth_numbers1).split("[\\[\\]]")[1].split(", "); 
                    //System.out.println(Arrays.toString(a)); 
                    //text = text + Growth_nums + Growth_numbers1 + a +  Arrays.toString(a) + "\n";
                    //text = text + Growth_nums + Growth_numbers1 + "\n";
     
     
                    //For Loop is for console output.... Not GUI
                    for (int i = 1; i < 73; i++) 
        	        {
        	            show_text(i, Growth_numbers1);
        	        }
        	       //Nums = Arrays.toString(Growthnumbers1);
        	       //System.out.println(Nums);
                    //System.out.println("the results= "+ java.util.Arrays.toString(Growth_numbers1));
     
                    text = text + java.util.Arrays.toString(Growth_numbers1);
                    for(int Texts : Growth_numbers1)
                    {
                    	text = text + Texts + System.getProperty("line.separator");          <=== made change here... and it prints zeros in column form
                    }
                    //textArea.append(Growth_nums + "\n");
                }

  21. #21
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Java GUI Problem, I am having trouble getting my TextArea to resemble console output.

    Where is the loop that wraps the 4 steps from post#7?

    Do some more debugging. Add a println() inside of the loop that goes through the results array and have it print out the test number and the results count. That should print something like what you want to see in the textarea. 73 lines with this:
    test# count
    test# count
    test# count
    ...
    If you don't understand my answer, don't ignore it, ask a question.

  22. #22
    Junior Member
    Join Date
    Sep 2014
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java GUI Problem, I am having trouble getting my TextArea to resemble console output.

    I have work in a bit, I will have to get back to you later with my results...


    Thanks

  23. #23
    Junior Member
    Join Date
    Sep 2014
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java GUI Problem, I am having trouble getting my TextArea to resemble console output.

    Hey Norm, Thanks for all the help...... I made a few changes and was finally able to figure out what my code needed.

         for loop(int j; j < 73 < j++)
      	textArea.append((j + 1) + " : " + Growth_numbers1[j] + "\n");

    The only thing I am curious about is why is my exception still being thrown?

    java.lang.NullPointerException
    Why is this exception being thrown.
    at RecurringGrowthCells.main(RecurringGrowthCells.jav a:36)

  24. #24
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Java GUI Problem, I am having trouble getting my TextArea to resemble console output.

    java.lang.NullPointerException
    Why is this exception being thrown.
    at RecurringGrowthCells.main(RecurringGrowthCells.jav a:36)
    There is a null value when line 36 is executed. Look at line 36, find the null value and then backtrack in the code to see why it is null.
    If you don't understand my answer, don't ignore it, ask a question.

  25. #25
    Junior Member
    Join Date
    Sep 2014
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java GUI Problem, I am having trouble getting my TextArea to resemble console output.

    ok cool, Thanks

Page 1 of 2 12 LastLast

Similar Threads

  1. How to clear Java output console
    By rita khatei in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 2nd, 2014, 03:42 PM
  2. Transferring console output to a textArea....how to make this happen?
    By jakhondi21 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 12th, 2013, 04:03 PM
  3. Problem diplaying output infor in GUI
    By jdubicki in forum AWT / Java Swing
    Replies: 3
    Last Post: December 15th, 2011, 08:55 AM
  4. From Console to GUI : problem !!
    By hexwind in forum AWT / Java Swing
    Replies: 33
    Last Post: August 20th, 2011, 10:50 PM
  5. Trouble apending a textArea with the contents of a parameter
    By bluetxxth in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 21st, 2010, 04:28 PM