Another option is to add both components to the JPanel but have one not visible. You can then make them appear and disappear at will without much effort.