In the java docs for java.awt.Component the method getComponentAt describes that it can return a component or a subcomponent.
What is a subcomponent?
Is there a way to retrieve all subcomponents from a component?
Subcomponent mentioned here: http://docs.oracle.com/javase/7/docs/api/java/awt/Component.html
awt uses
Containeras a special class ofComponentwhich can contain other components. So the enumeration of all components is calledContainer.getComponents(). Why they decided to have the subcomponent access in theComponentclass instead of theContainerclass, I don’t know, but that’s the way it is. Perhaps the reason is thatgetComponentAtwill also return the component for which the method was invoked, if there is no sub-component in that location, and if it actually contains the given position.So to find all subcompnents, check whether the component is a container. If it is not, then it cannot have subcomponents. If it is, then cast to
Containerand access them. Recurse if you need sub-sub-components as well.