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.

Results 1 to 7 of 7

Thread: tripple for loop problem

  1. #1
    Member
    Join Date
    Mar 2011
    Posts
    198
    My Mood
    Daring
    Thanks
    7
    Thanked 4 Times in 4 Posts

    Default tripple for loop problem

    so i'm having 3 for loops inside each other. First for loop will be for the panels creation, Second for loop is for the labels and the third for loop is for the JTextFields

    I have a tabbedPane with tabs Monday - Friday. Under each tab i wish it to be set out like this:

    MONDAY - TextBox
    MONDAY - TextBox
    MONDAY - TextBox

    Tuesday will of course be TUESDAY etc.. here is the code for the for loop:

     public void panelSetup(){
    	  for(int i = 1; i <= 6; i++){
    		  panel[i] = new Panel();		  
     
    		  for(int f = 0; f < 5; f++){
    			  panel[i].add(arrLabel[f][0]);
     
    		  for(int x = 0; x <= 8; x++){
     
     
    			  txtBox[x] = new JTextField("", 10);
    			  panel[i].add(txtBox[x]); 
     
    			  }
     
    		  }
     
    	  }
     
      }

    The problem is that it seems to be adding up the ammount of text boxes per tab and displaying them in each tab. so instead of 9 textfields its displaying 45 per tab. and the JLabel is displaying only on the final tab which is displaying 1 of each day before that tabs 9 textboxes start. image provided below..

    Attachment 622


  2. #2
    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: tripple for loop problem

    What layout manager are you using? It looks like flow. If you want a grid, you should use a layout manager that will create a grid.

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: tripple for loop problem

    Please don't post the same question twice to the forums. Your other thread has been removed.

  4. #4
    Member
    Join Date
    Mar 2011
    Posts
    198
    My Mood
    Daring
    Thanks
    7
    Thanked 4 Times in 4 Posts

    Default Re: tripple for loop problem

    was actualy planning on using spring layout

  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: tripple for loop problem

    Is it working for you?

  6. The Following User Says Thank You to Norm For This Useful Post:

    macko (June 20th, 2011)

  7. #6
    Member
    Join Date
    Mar 2011
    Posts
    198
    My Mood
    Daring
    Thanks
    7
    Thanked 4 Times in 4 Posts

    Default Re: tripple for loop problem

    i am about to give it a test ive just finished the technical document for the project. will post here with results shortly

  8. #7
    Member
    Join Date
    Mar 2011
    Posts
    198
    My Mood
    Daring
    Thanks
    7
    Thanked 4 Times in 4 Posts

    Default Re: tripple for loop problem

    seem to have fixed the problem. just had to sit and think i had ended up using

    if (i % 7 == 6) { a++; }

    seemed to work perfectly. seems all i have left is the calculations as i have just completed the file reading/writing. although the calculations i shall do myself. thanks for the help you've given me norm . i think u do deserve a thanks even if i was extremely lazy to debug myself lol ^^

Similar Threads

  1. While loop problem
    By ak120691 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 8th, 2011, 04:09 PM
  2. Problem with Loop
    By Dragonkndr712 in forum What's Wrong With My Code?
    Replies: 13
    Last Post: February 8th, 2011, 12:12 PM
  3. [SOLVED] While Loop Problem :(
    By faisalnet5 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 10th, 2010, 11:23 AM
  4. Little Loop Problem
    By chronoz13 in forum Loops & Control Statements
    Replies: 1
    Last Post: October 17th, 2009, 04:40 AM