In my project I've got a JPanel (bottomPanel) in a JFrame that needs to be swapped so I'm using a CardLayout on bottomPanel.
In my parent JFrame I've essentially got this code in a method (setBottomPanel):
bottom.add(p.toString(),p);
bottomLayout.show(bottom, p.toString());
And I call it once in the parent JFrame's constructor and it works fine. However, I'm passing a reference to this parent JFrame to other JPanels and if I call setBottomPanel() on the reference it has no effect, the panel doesn't change.
I did have it using bottomLayout.next(bottom)
and this did change the panel, but to an empty one.
Update:
It appears it IS loading correctly, I changed the code back to calling next()
but the JPanel that is being passed is empty. Could this be because I'm using GridLayout on the JPanel that is being added to the bottomPanel? I'm not passing in the layout reference at all...