I have a swing application with JPanel that acts as a view port for my application. I want my application to remove all components inside the viewport when a user clicks on a menu item or button and creates new components in it. I know how to remove a component from the container, it is not clear which component is currently inside the view port. Therefore, I think I can not use the code below:
viewport.remove(component); viewport.revalidate(); viewport.repaint();
my questions:
How to remove all components inside a container without knowing which component to remove?
Is it possible to remove all components and create other components and insert them correctly in the view port?
source share