javaswingjpaneljbuttonjcomponent

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


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.


Solution

  • 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.