0

I am having trouble getting my console/Terminal output to resemble my GUI output in JTEXTAREA. I am expecting the data to appear on multiple lines but it isn't. Can someone take a look and offer an opinion, solution, to my code problem. Thanks!

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]++;
            }

            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);
            }
        }

    } 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);
}

  public static int[] show_text(int i, int[] Growth_numbers1)
  {
      System.out.printf("%-10s\n", new Object[]{ i + ": " + Growth_numbers1[i] });
      return Growth_numbers1;
  }
}

Here is a sample of col1.csv showing the date and test number.

6/17/14    18

6/18/14    18

6/19/14    18

6/20/14    18

6/21/14    18

6/22/14    1

6/23/14    2

6/24/14    9

6/25/14    2

I expect the output to appear like this:

1: 4
2: 10
3: 4
4: 4
5: 6
6: 1
7: 2
8: 5
9: 4
10: 3
11: 3
12: 1
13: 2

But instead of appearing on multiple lines as I expect, it all gets combined onto a single line.

bad-output good-output

Cory Klein
  • 51,188
  • 43
  • 183
  • 243
New_Guy25
  • 1
  • 1
  • What exactly is the problem? Can you provide an example of how it looks now and how you want it to look? – Cory Klein Oct 01 '14 at 15:48
  • Okay, I can see that you don't need what you just posted, but we can't help you change it when we don't know "what you need." You need to update the question to add more details about specifically what is wrong, and *why* it is wrong, and what you want it to do. – Cory Klein Oct 01 '14 at 15:59
  • Sorry, I'm doing the best I can. This is my first time on this site. I have posted a link below under the code. – New_Guy25 Oct 01 '14 at 16:10
  • You're fine - my patience was just a little thin this morning. So it looks like the problem is that all your data gets put on a single line, and you want it on multiple lines? – Cory Klein Oct 01 '14 at 16:16
  • yes, I would like my data on multiple lines. Here is the link of what I am trying to do. http://www.javaprogrammingforums.com/awt-java-swing/39910-java-gui-problem-i-am-having-trouble-getting-my-textarea-resemble-console-output.html#post158544 – New_Guy25 Oct 01 '14 at 16:23
  • Can you post a few lines of `col1.csv` too? Don't add it in the comments, put it in the question. Also update the question stating that you are expecting the data to appear on multiple lines but it isn't. – Cory Klein Oct 01 '14 at 16:25
  • I have updated my original posting to show a few lines of my col1.csv file and a few lines of my consle output. – New_Guy25 Oct 01 '14 at 16:42
  • Okay, I think I'm starting to get an idea of what your problem is. So which place has the problem, the console output or the GUI output? – Cory Klein Oct 01 '14 at 16:49
  • http://stackoverflow.com/questions/8858584/how-to-wrap-text-in-a-jtextarea may be helpful – rogerdpack Oct 01 '14 at 16:49
  • the GUI output has the problem. – New_Guy25 Oct 01 '14 at 16:50
  • I just tried the line wrapper, it did not quite do anything. – New_Guy25 Oct 01 '14 at 16:53
  • System.out.println("the results= "+ java.util.Arrays.toString(Growth_numbers1)); – New_Guy25 Oct 01 '14 at 16:54
  • The print statement just confirms that my Growth_number1 array contains my results. 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] – New_Guy25 Oct 01 '14 at 17:00

0 Answers0