title: Textarea maximalsize in Borderlayout
body: <p>I have a simple problem but I found no good solution for it. I have a <code>JFrame</code> with components at <code>SOUTH</code>, <code>NORTH</code>, <code>EAST</code>, and <code>CENTER</code>. On <code>CENTER</code> is my problem. On center I have a <code>JPanel</code> with a <code>Borderlayout</code> and 2 <code>JTextAreas</code> (one on <code>NORTH</code>, one int the <code>CENTER</code>).</p>
  
  <p>I want that the first panel begins always on top of the panel and stretch maximum (if needed) to the middle of the panel, not more. The second area should begin at the end of the first area. If one of both text areas is to big, there should appear a <code>JScrollPane</code>. </p>
  
  <p>What is the best Way to realize that? Should I use a other layout for the panel?</p>
  
  <p>Here is my little execute example for it:</p>
  
  <pre><code>public class myGUI {
  
      public static void main(String[] args) {
          new myGUI();
      }
  
      public myGUI() {
          JFrame frame = new JFrame();
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setSize(400, 400);
  
      //Add Content at South, West and North....
          JPanel centerPanel = new JPanel();
          centerPanel.setLayout(new BorderLayout());
          centerPanel.add(new JScrollPane(new JTextArea("AREA")), BorderLayout.NORTH);
          centerPanel.add(new JScrollPane(new JTextArea("AREA2")), BorderLayout.CENTER);
          frame.add(centerPanel);
          frame.setVisible(true);
      }
  }
  </code></pre>
  
  <p>Possible scenarios of the center panel:</p>
  
  <p><img src="https://i.stack.imgur.com/RPRgU.png" alt="enter image description here"></p>
  
  <p><strong>SOLUTION with help from @Hovercraft Full Of Eels</strong> </p>
  
  <pre><code>public class MyGUI {
  public static void main(String[] args) {
      new MyGUI();
  }
  
  private static GridBagConstraints constraint = new GridBagConstraints();
  
  public MyGUI() {
      JFrame frame = new JFrame();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setSize(400, 400);
  
      frame.add(new JLabel("NORTH!"), BorderLayout.NORTH);
      frame.add(new JLabel("EAST!"), BorderLayout.EAST);
      frame.add(new JLabel("SOUTH!"), BorderLayout.SOUTH);
  
      JPanel centerPanel = new JPanel();
      centerPanel.setLayout(new GridBagLayout());
      changeConstraint(0,0);
  
      JTextArea text1 = createTextArea("11111111111111");
      centerPanel.add(text1, constraint);
      changeConstraint(0,1);
  
      JTextArea text2 = createTextArea("2222222222222");
      centerPanel.add(text2, constraint); 
      JScrollPane scroll = new JScrollPane(centerPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
      frame.add(scroll, BorderLayout.CENTER);
      frame.setVisible(true);
  }
  
  /**
   * Create a Gridbag Constraint
   * @param text
   * @return
   */
  private void changeConstraint(int gridx, int gridy){
      constraint.anchor = GridBagConstraints.FIRST_LINE_START;
      constraint.fill = GridBagConstraints.HORIZONTAL;
      constraint.weighty = 0;
      constraint.weightx = 1.0;
      constraint.gridx = gridx;
      constraint.gridy = gridy;
  }
  
  /**
   * Create a Textarea
   * @param text
   * @return
   */
  private JTextArea createTextArea(String text){
      JTextArea textarea = new JTextArea(text);
      textarea.setWrapStyleWord(true);
      textarea.setLineWrap(true);
      return textarea;
  
  }
  </code></pre>
  
  <p>}</p>