title: How to update the JFrame Content Pane from calling a method?
body: <p>Okay currently I am trying to make a multi-window program. </p>
  
  <p>And from seeing other forums, it seems for you to do that in Java JFrame you must update its content pane by adding the <code>new JComponent(new window/layout/idk)</code>, set the current window visibility to false, set the new one visibility to true and validate &amp;/ repaint content pane:</p>
  
  <pre><code>    contentPane.add(newWindowPanel);
      currentWindowPanel.setVisible(false);
      newWindowPanel.setVisible(true);
      contentPane.validate();
      contentPane.repaint();
  </code></pre>
  
  <p>now, what I am trying to do and partially have done is created a class that extends <code>JPanel</code>, and this class stands to be the top of an hierarchy for many other JPanel classes that I am going to create. </p>
  
  <p>Within that class I have this method :</p>
  
  <pre><code>    public void updateContentPane(Container contentPane, JPanel currentPanel, JPanel nextPanel){
  
      contentPane.add(nextPanel);
      currentPanel.setVisible(false);
      nextPanel.setVisible(true);
      contentPane.validate();
      contentPane.repaint();
  } 
  </code></pre>
  
  <p>When I call this method within one of the child classes, it doesn't work.</p>
  
  <pre><code>    updateContentPane(WindowMain.contentPane, this, mainMenuClass);
  </code></pre>
  
  <p>Each of the child class inherits the JPanel characteristic. </p>
  
  <p>"WindowMain" is a class that extends JFrame, and "contentPane" is a static container variable that holds the frame contentPane. </p>
  
  <p>"this" represents the current class (inherits JPane), but "this" don't actually work <code>new Object()</code> works.</p>
  
  <p>"mainMenuClass" also inherits JPanel and has already been instantiated in this class.</p>
  
  <p>My goal is to simply jump from one scene to the other by calling that method. But it goes through the code (debug) but nothing happens. But, if I take the code within the method and place it inside a button listener it works fine. </p>
  
  <p>(Sorry for all this writing, it will probably bring some confusion at that, but I need to figure this out nonetheless, and I will set condition for when the contentPane already contains a class, so no need to mention it)</p>