The error is not because the LayeredPane isn’t a Container, the LayeredPane really is one, the issue seems to be the error that the code is not finding the expected component. In the setup, a container is added and located at index 6, but in replay the LayeredPane’s list of components is empty or it is none matching with what was expected. The result of this contributes to an IndexOutOfBoundsException when trying to get a component that isn’t ther. Instead, it might be better to check if the container actually exists, or at least keep a direct reference to it rather than by its index.