title: Dynamic JFrame in java
body: <p>I have a project and I need to know how to adding a component in a JFrame when pressing a JButton.
  I have added a panel into panel by this code:</p>
  
  <pre><code>private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
  
      colorPanel color0=new colorPanel();
      color0.setBounds(5,150+nb,300,120);
      color0.setLayout(new FlowLayout());
  
      this.getContentPane().add(color0);
      this.validate();
  
      System.out.println("add couleur:"+nb);
      nb+=50;
  }
  </code></pre>
  
  <p>It works but the problem is that the component is deleted when I maximize or minimize the JFrame.
  Thanks.</p>