title: JPanels in JPanel
body: <p>I have a problem with Java JPanels. I would like to put 2 JPanels with different layouts into one JPanel which is also has a layout. Is it even possible to make it work?</p>
  
  <pre><code>    BibP()
  setLayout(new GridLayout(5, 1)); //The big JPanel
  add(new A(), new FlowLayout(4));
  add(new B(), new GridLayout(7,2));    
  </code></pre>
  
  <p>Both A and B are classes extends as JPanels and no matter what I changed or commented B is always appears in 1 row.
  I have 4 elements added to A and 14 to B (JLabels and JTextAreas) and there is not much code in them only the adds and some calculation.</p>
  
  <p>The problem might be in the JFrame where I am trying to put the big JPanel.</p>
  
  <pre><code>    JFrame.this.add(new BigP(),BorderLayout.CENTER);    
  </code></pre>
  
  <p>Edit:</p>
  
  <pre><code>    public class BigP extends JPanel{
  //Labels and TextAres
  
  public class A extends JPanel{
      public A(){
          setBorder(new EmptyBorder(0, -50, 0, 0));
          //get date and add to textareas
          //add the label and textareas
  }
  }
  
  public class B extends JPanel{
      public B (){
          setBorder(new EmptyBorder(0, -50, 0, 0));
          setBackground(Color.red);
          //colum longs for text areas less then 5
          //add labels and textareas
      }
  }
  
  public BigP(){
      setLayout(new GridLayout(5, 1));
      setBorder(new EmptyBorder(3,-160,0,0));
  
      add(new A(), new FlowLayout(4));
      add(new B(), new GridLayout(7,2));
  }
  }    
  </code></pre>
  
  <p>Thanks for helping.</p>
  
  <p>After a few tries:</p>
  
  <p>If I used this:</p>
  
  <pre><code>    add(new B(), new GridLayout(7,2));
  </code></pre>
  
  <p>I get this in B when I printlned the layout:</p>
  
  <p>java.awt.FlowLayout[hgap=5,vgap=5,align=center]</p>
  
  <p>If I set the Layout in B:</p>
  
  <pre><code>    setLayout(new GridLayout(7, 2));
  </code></pre>
  
  <p>The information is correct:</p>
  
  <p>java.awt.GridLayout[hgap=0,vgap=0,rows=7,cols=2]</p>
  
  <p>But there is only 2 JTextAreas vissible where should be 14 elements.</p>