Search code examples
javaswingjframejpanelvisible

Having a dilemma with jpanels becoming visible


Ok here's my dilemma I add three panels to my JFrame. The first(invisible) the second(visible) and the third(invisible).. I use the first panel as a menu, when you select a option the first panel is made(visible) then third panel is made (visible) and the second (invisible) after your done on the third panel (the only one visible to the user) it becomes invisible. No first panel shows up. Just white. Any help? Thanks guys!


Solution

  • Check this out. Alternatively, you can follow the solution that I was taught:

    Invoke the setContentPane() method in the Frame class.

         JFrame frame = new JFrame("Press Your Luck");
         frame.setSize(sizeX, sizeY);
         frame.setLocation(locX, locY);
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         frame.setContentPane(new Panel1());
         frame.setVisible(true);
    

    Each time you want to change panels, just invoke frame.setContentPane(PanelName);