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.


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

Results 1 to 2 of 2

Thread: Printing Output from an array in a gui form.

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Thanked 0 Times in 0 Posts

    Unhappy Printing Output from an array in a gui form.

    I'm using Netbeans to creat a Java Swing Gui form. I'm stuck creating output in an array that will print out in a text area box.

           double tutorArray [] [] = new double [4][2];
           int counter;
           int i  = 0;
           int j = 0;

    The user inputs two values at a time and then presses the enter button:

     double salary = Double.parseDouble (salaryTextField.getText ());
           double week = Double.parseDouble (wagesTextField.getText ());
             {if (minutes <= 0 || minutes > 4500|| wages <= 4) 
              throw new IllegalArgumentException ();
          catch (IllegalArgumentException exception)
           dataTextArea.setText("Invalid input.  Please try again.");
            tutorArray [counter] [0] = salary;
            tutorArray [counter] [1] = weeks;
             for (int i = 0; i <= 4 ; i++){
              for (int j = 0; j <= 2; j++) {
                 String line = String.format ("%2d", tutorArray[i][j]);
                 dataTextArea.append (line);

    3. Once the user finishes entering his information, a 2d Array should be generated when he presses the "run report" button:

     private void runReportButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                
            // TODO add your handling code here:

    I have tried multiple times to write the code for a 2d array that has 4 rows and two columns containing the information entered by the users - minutes and wages.

    Any pointers?
    Last edited by Norm; December 28th, 2012 at 08:47 AM. Reason: Removed = Java from code tags

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Eastern Florida
    Thanked 2,710 Times in 2,660 Posts

    Default Re: Printing Output from an array in a gui form.

    What is in the array after the code assigns values to it?
    Use the Arrays class's deepToString() method to format the array for printing:
    System.out.println("an ID "+ java.util.Arrays.deepToString(theArrayName));

    Can you explain what the code does and what it is not doing that you want it to do?
    Obviously this needs to be replaced with some code:
    // TODO add your handling code here:
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. help with printing output in columns
    By jblankinship in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 14th, 2012, 01:03 PM
  2. Problem with running a GUI Form
    By Pane87 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: August 4th, 2012, 12:48 PM
  3. Problem with running a GUI form
    By Pane87 in forum AWT / Java Swing
    Replies: 0
    Last Post: August 4th, 2012, 06:03 AM
  4. Replies: 1
    Last Post: September 28th, 2011, 07:29 AM
  5. [SOLVED] Printing Array without printing empty elements
    By CarlMartin10 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 12th, 2010, 02:41 AM