-1

The following method has the end result I need. The problem is, when the method is called, the starting pnlMain stays visible until the new pnlMain is created and replaces the original. The point of this method is to change the panel by creating a new one but this process takes a little time, so I am trying to have the "load" panel show up during that time.

public void changePanel() {
    remove(pnlMain);
    add(load);
    repaint();
    pnlMain = new HunterPanel(settings); // HunterPanel extends JPanel
    remove(load);
    add(pnlMain);
    repaint();
    pnlMain.requestFocus();
}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433

1 Answers1

3

"Changing Panels during runtime"

The correct way is to use a CardLayout that will allow you to switch between views. See How to Use CardLayout for more details. See a simple example here

But just to let you know where you're going wrong in your code, if you remove and add components at runtime, you need to revalidate(). But in your case, go with the CardLayout. After you learn it, you be happy you did :-)

Community
  • 1
  • 1
Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720