0

In my program I go from the log in to the main menu,to different areas of the site.

    jPanel2.removeAll();
    Items panel = new Items(); 
    jPanel2.add(panel); 
    jPanel2.repaint();
    jPanel2.revalidate();

I thought that I found a way to change jpanels so that I can go from one jpanel to another which in the same screen.

The problem with the above code is that each time I change jpanels, the old jpanel isn't gotten rid of, it is staying there, meaning whenever I change jpanels the jpanel slowly gets lower on the page due to it being put underneath the other jpanels that were created before it.

Is there a way to get rid of the jpanels so that when I go to a new jpanel it doesn't slowly lower down the page?

Pirates
  • 115
  • 1
  • 2
  • 7

1 Answers1

0

I think you should use CardLayout to achieve this requirement.

Check this below link.

https://docs.oracle.com/javase/tutorial/uiswing/layout/card.html

or this SO

Changing Panels using the Card layout

Community
  • 1
  • 1
Beniton Fernando
  • 1,533
  • 1
  • 14
  • 21