4

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()).

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Evorlor
  • 7,263
  • 17
  • 70
  • 141

1 Answers1

7

Nevermind. It was hiding in the Container API.

myPanel.getComponentCount();
Evorlor
  • 7,263
  • 17
  • 70
  • 141