You should call the revalidate()
and repaint()
method when you switch the panes.
frame.getContentPane().revalidate();
frame.getContentPane().repaint();
From add method of Container
.
Note: If a component has been added to a container that has been displayed, validate must be called on that container to display the new component. If multiple components are being added, you can improve efficiency by calling validate only once, after all the components have been added.
From remove method of Container
.
Note: If a component has been removed from a container that had been displayed, validate() must be called on that container to reflect changes. If multiple components are being removed, you can improve efficiency by calling validate() only once, after all the components have been removed.
Edited as per camickr's comment.