Count number of Children in JPanel

2.6k Views Asked by At

I have a JPanel, to which I have added an unknown number of JComponents. How can I count the number of JComponents in that JPanel?

I have looked at the API, but I see no method for retrieving the children so that I can count them. Is this possible to count the children afterwards? Or do I have to go back and count the children as I am adding them?

By child, I mean a JComponent on which is from: myPanel.add(new JComponent()).

1

There are 1 best solutions below

0
On BEST ANSWER

Nevermind. It was hiding in the Container API.

myPanel.getComponentCount();