Question

I'm making a GUI project in NetBeans. I have a JFrame and 3 JPanels. Only one of the JPanels should be displayed at a time. The JPanel that is displayed should be changed using a menu option (the listeners work).

My question is, how do I switch them out? I've tried removing the old JPanel and putting in the new JPanel. I've tried adding a fourth JPanel into the JFrame and having all three JPanels exist within the fourth, so I can use removeAll() (bad technique, but I was desperate). I've tried redirecting the object reference so that it points to the new JPanel instead of the old one. In each case, I've finished off the code snipped with

    revalidate();
    repaint();

To no avail. I've seen a lot of talk about CardLayout and GroupLayout but I have no idea how to implement them using the NetBeans GUIBuilder. Could one of you fine people tell me how to switch out the JPanels?

Was it helpful?

Solution

Use a LayeredPane. 30charactermin

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top