title: I need a JPanel to be displayed when I click on a JToggleButton
body: <p>I have a JFrame divided in two on one side I have a JPanel that has some JToggleButtons on it. in the other side I need to show the right JPanel when one of the JToggleButtons is  clicked. Right now am using only one thread to do this.</p>
  
  <p>here is the JFrame</p>
  
  <pre><code>public class AppFrame extends JFrame{
      private JPanel content ;
      private JPanel menu;
  
      public AppFrame() {
          super("Title");
          setLayout(BorderLayout());
          //content is gonna hold JPanel1 or JPanel2
          content = new JPanel();
          menu = new menu();
          this.add(menu, BorderLayout.WEST);
          this.add(content , BorderLayout.CENTER);
      }
  
      public void setContet(JPanel activePanel){
          content = activePanel;
          this.add(content , BorderLayout.CENTER);
      }
  }
  </code></pre>
  
  <p>here is the JPanel holding the JToggleButtons (MenuJPanel)</p>
  
  <pre><code>public class MenuJPanel extends JPanel{
  private final LayoutManager innerLayout = new GridLayout(3,1,1,1);
  private final JToggleButton button1;
  private final JToggleButton button1;
  
  public MenuPanel() {
      super();
      SwitchHandler sHandler = new SwitchHandler();
      this.setLayout(innerLayout);
      this.add(button1);
      this.add(button2);
      button1.addActionListener(sHandler);
      button2.addActionListener(sHandler);
  }
  
  class SwitchHandler implements ActionListener{
  
      @Override
      public void actionPerformed(ActionEvent e) {
          if (e.getSource() == button1){
              button2.setSelected(false);
              //at this point I want the frame to display JPanel1
              //I tried this
              AppFrame frame = (AppFrame)getTopLevelAncestor();
              frame.setContet(new JPanel1());
          } else {
              button1.setSelected(false);
              //at this point I want the frame to display JPanel2                
              //I tried this
              AppFrame frame = (AppFrame)getTopLevelAncestor();
              frame.setContet(new JPanel2());
          }
      }
  }
  </code></pre>
  
  <p>Can someone tell me how can I open these panels in the frame when the event is triggered.
  thanks</p>