title: How to remove existing JPanel and continuously implement action listener?
body: <p>I am trying to create a <code>JFrame</code>/<code>JPanel</code> GUI for a personal project I'm working on. I want to distinguish between beta modes and launch modes through two menus that are togged by a beta and a launch button respectively. Since implementing the second panel, I haven't been able to get the action listener to continue responding to the buttons (after it renders the new menus) nor have I been able to get the old panel to go away, I am fairly sure I'm just writing over it. I am having trouble with the action listeners which shouldn't be having any issues since they're added just as I create the buttons and having trouble figuring out the best way to deal with duplicate panels.</p>
  <p>Below are some snippets of my code</p>
  <p>I've tried using <code>remove(panel)</code>, adding a new panel, a new frame, etc.</p>
  <p>When I move the add call to <code>BorderLayout.SOUTH</code>, I can see that the new panel has my original mode menu and my 2 <code>JComboBox</code> controls rendered as desired, but in the original mode menu is still there and no longer works when I click. The new menu at the bottom lets me click once and prints my statement TWICE before stopping responding.</p>
  <p>If I don't click the BETA mode button, and just click the launch button, it will print twice each time for the bottom, for the top it prints once and lets me do it as much as I want.</p>
  <pre><code>protected JButton betaModeButton, launchModeButton;
      JPanel modePanel;
      public View() {
      setLayout(new BorderLayout());
      setup();
  }
  
  public void setup() {
      add(modeButtons(), BorderLayout.NORTH);
      System.out.println(&quot;setup&quot;);
  }
  
  
  /**
   * choose your mode for testing or implementation
   * @return
   */
  protected JPanel modeButtons() {
      modePanel =  new JPanel(new GridLayout(1,2));
      
      betaModeButton = new JButton(&quot;BETA&quot;);
      betaModeButton.setOpaque(true);
      betaModeButton.addActionListener(this);
      
      launchModeButton = new JButton(&quot;LAUNCH&quot;);
      launchModeButton.setOpaque(true);
      launchModeButton.addActionListener(this);
      
      modePanel.add(betaModeButton);
      modePanel.add(launchModeButton);
  
      return modePanel;
  }
  
  private JPanel betaMenu() {
      
      System.out.println(&quot;Beta Menu should be added&quot;);
      JPanel comboMenu=new JPanel (new GridLayout(2,1));
      JPanel betaMenu=new JPanel(new GridLayout(1,2));
  
      //readd combo buttons
      comboMenu.add(modeButtons(), BorderLayout.NORTH);
  
      legShape= new JComboBox();
      legShape.addItem(&quot;Circle&quot;);
      legShape.addItem(&quot;Square&quot;);
      legShape.addItem(&quot;triangle&quot;);
      betaMenu.add(legShape);
      
      center= new JComboBox();
                   &quot;code repeats structure
  
      betaModeButton.addActionListener(this);
      launchModeButton.addActionListener(this);
      
      comboMenu.add(betaMenu);
      return comboMenu;
  }
  </code></pre>
  <p>My action performed call is:</p>
  <pre><code>add(betaMenu(),BorderLayout.SOUTH);
  validate();
  </code></pre>
  <p>The buttons should print out every time I click and the top menu should disappear</p>