How can I get all the components of a panel in Java Swing?

user1918908 picture user1918908 · Mar 31, 2013 · Viewed 16.1k times · Source

How can I get all the components of a panel in Java Swing?

Is there any method like foreach in C# to deal all the child components of a JPanel?

Answer

Howard picture Howard · Mar 31, 2013

You may use the method getComponents:

Component[] components = jpanel.getComponents();