Can't a Swing component be added to multiple containers?

Juan Diego picture Juan Diego · Jan 6, 2011 · Viewed 7.4k times · Source

I'm trying (testing something else) to add one JButton reference into two JPanels to test it, and it disappears from the first panel it was added to!

So, can't a Swing component be added to multiple containers?

Thank you in advance.

Answer

jzd picture jzd · Jan 6, 2011

From: http://download.oracle.com/javase/tutorial/uiswing/components/toplevel.html:

Each GUI component can be contained only once. If a component is already in a container and you try to add it to another container, the component will be removed from the first container and then added to the second.