title: Loading a panel from a different class
body: <p>I have two classes. The main class has a JFrame and holds a button, which after clicking the button, it loads a panel from a different class and locate it in the button of the frame.</p>
  
  <p>I could achieve it, but I have to re-size the frame then the additional panel appears, otherwise it is hidden.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public class PanelLoader {
  
      public static void main(String[] args) {
          // TODO code application logic here
          JFrame frame = new JFrame("Layout");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setSize(400, 300);
          JPanel mainPanel = new JPanel(new BorderLayout());
  
          JButton press = new JButton("press");
          press.addActionListener(new ActionListener(){ //ActionListener, on click it opens a file choser, 
             @Override                                      //selects a directory then gives it to srcDirField
             public void actionPerformed(java.awt.event.ActionEvent event){
                  JPanel mine = ClassWhereStored.newJPanel();
                  mainPanel.add(mine, BorderLayout.SOUTH);
             }
          });
  
          mainPanel.add(press, BorderLayout.NORTH);
          frame.add(mainPanel);
  
          frame.setVisible(true);
      }
  }
  </code></pre>
  
  <p><strong>Second Class:</strong></p>
  
  <pre><code>public class ClassWhereStored {
      public static JPanel newJPanel(){
          JPanel panel = new JPanel();
          panel.setBackground(Color.yellow);
          JLabel test= new JLabel("Some Text");
          panel.add(test);
          return panel;
      }
  }
  </code></pre>
  
  <p>So what is wrong with this frame that shows the additional panel only if I re-size the frame?</p>