When dynamically adding/removing components from a container, it’s necessary to invoke revalidate()
/validate()
and repaint()
afterward. The former will force the container to layout its components again and the latter will remove any visual “artifacts”.