I was dealing with a similar problem, I wanted to change the panel contained in the panel at runtime
After some testing, retesting and a lot of unsuccessful my pseudo-algorithm:
parentPanel: contains the panel we want to remove
childPanel: the panel we want to switch
parentPanelLayout: parentPanel layout
editParentLayout (): builds a parentPanel with different childPanel and NEW parentPanelLayout each time
parentPanel.remove(childPanel); editParentLayout(); parentPanel.revalidate(); parentPanel.repaint();
source share