sutoL
sutoL

Reputation: 1767

Reusing same JPanel in Java swing

I have two JPanels that needs to add a JPanel into it, however only the last added JPanel does it show the JPanel. As shown below:

holderPanel1.add(dataPanel);
holderPanel2.add(dataPanel);

only holderPanel2 shows the dataPanel, but holderPanel1 does not show.

Upvotes: 3

Views: 1739

Answers (1)

MByD
MByD

Reputation: 137442

UI Components (such as JPanel) are the underline representation of things you see on the screen (location, parent, sub-components etc.), so each panel that you see on the screen has to have a separate underline representation, so you cannot add a panel to two different panels, you need to create two separate panels.

Upvotes: 6

Related Questions