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 3 of 3

Thread: Loop through Components of a Component

  1. #1
    Member
    Join Date
    Apr 2013
    Posts
    43
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Loop through Components of a Component

    Hello!

    I'm having trouble to loop through all the components of a JFrame. The program is going to be a Sudoku-solver, which means that I have 9 rows and 9 columns of JTextFields. Each textfield is in one of 9 JPanels and each JPanel is in one big JPanel. Now I want to loop through every textfield, and my code is shown below:

    Component[] c = p.getComponents();
     
            for (int i = 0; i < c.length; i++) 
            {
     
                Component[] c2 = c[i].getComponents(); 
     
                for (int 0 = 1; j < c2.length; j++)
                {
     
                }
     
            }

    The big JPanel is p, and what I want is to loop through each component in p, and each component in the components of p. I'm getting an error:

    "Cannot find symbol
    Symbol: method getComponents()
    Location: Class Components"

    Can someone tell me what I'm doing wrong.

    Hank


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Loop through Components of a Component

    Can you put all the components into an array when try are created, instead of trying to find them by searching the container they are in?

    Cannot find symbol
    Symbol: method getComponents()
    Location: Class Components
    Does the Components class have a method: getComponents()?
    If you don't understand my answer, don't ignore it, ask a question.

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

    iHank (December 2nd, 2013)

  4. #3
    Member
    Join Date
    Apr 2013
    Posts
    43
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: Loop through Components of a Component

    [QUOTE=Norm;132364]Can you put all the components into an array when try are created, instead of trying to find them by searching the container they are in?

    Thank you very much! I'm still at that point where I'm figuring out what's possible and answers like this is very helpful.

Similar Threads

  1. Components not appearing (need help!)
    By hawkeye01 in forum Object Oriented Programming
    Replies: 6
    Last Post: March 24th, 2013, 09:41 AM
  2. Components?
    By Gravity Games in forum Java Theory & Questions
    Replies: 31
    Last Post: August 5th, 2012, 04:20 PM
  3. Laying out components.
    By newbie in forum AWT / Java Swing
    Replies: 1
    Last Post: August 14th, 2011, 04:37 AM
  4. Interaction between components.
    By SyntheticD in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 9th, 2011, 07:32 PM
  5. Getting Size of Components
    By aussiemcgr in forum AWT / Java Swing
    Replies: 3
    Last Post: July 26th, 2010, 03:41 PM