title: MigLayout resizing with JScrollPane
body: <p>I searched a little bit and did not find a good answer to my problem.</p>
  
  <p>I am working on a gui that has to be resizable. It contains a status <code>JTextArea</code> that is inside a <code>JScrollPane</code>. And this is my problem. As long as I don't manually resize my JFrame, the "initial" layout is kept and everything looks fine. As soon as I manually resize (if the <code>JTextArea</code> is already in scrolled mode), the layout gets messed up.</p>
  
  <p>Here is a SSCCE (I got rid of most of the parts while keeping the structure of the code. I hope it's more readable that way):</p>
  
  <pre><code>import java.awt.Color;
  import java.awt.Font;
  
  import javax.swing.BorderFactory;
  import javax.swing.JComboBox;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.JPanel;
  import javax.swing.JScrollPane;
  import javax.swing.JSeparator;
  import javax.swing.JSlider;
  import javax.swing.JTabbedPane;
  import javax.swing.JTextArea;
  import javax.swing.JTextField;
  import javax.swing.border.TitledBorder;
  
  import net.miginfocom.swing.MigLayout;
  
  public class Tab extends JFrame {
    private static final long serialVersionUID = 1L;
    private JTextArea messageTextArea;
    private JPanel optionPanel, messagePanel;
    private JTabbedPane plotTabPane;
  
    public static void main(String[] args) {
      final Tab tab = new Tab();
      tab.setSize(1000, 600);
      tab.setVisible(true);
      new Thread(new Runnable() {
        @Override
        public void run() {
          int count = 0;
          tab.printRawMessage("start");
          while (true) {
            try {
              Thread.sleep(200);
            } catch (InterruptedException e) {}
            tab.printRawMessage("\ntestMessage" + count++);
          }
        }
      }).start();
    }
  
    public Tab() {
      super();
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      initComponents();
    }
  
    private void initComponents() {
      JPanel mainPanel = new JPanel();
      mainPanel.setLayout(new MigLayout("insets 0", "", ""));
      mainPanel.add(getLeftTopPanel(), "shrinky, top, w 450!");
      mainPanel.add(getRightPanel(), "spany 5, wrap, grow, pushx, wmin 400");
      mainPanel.add(getMessagePanel(), "pushy, growy, w 450!");
  
      JScrollPane contentScrollPane = new JScrollPane(mainPanel);
      contentScrollPane.setBorder(BorderFactory.createEmptyBorder());
      setContentPane(contentScrollPane);
    }
  
    protected JPanel getLeftTopPanel() {
      if (optionPanel == null) {
        optionPanel = new JPanel();
        optionPanel.setBorder(BorderFactory.createTitledBorder(null, "Configuration", TitledBorder.LEFT, TitledBorder.TOP, new Font("null", Font.BOLD, 12), Color.BLUE));
        optionPanel.setLayout(new MigLayout("insets 0", "", "top, align 50%"));
  
        JLabel label = new JLabel("Choose");
        label.setHorizontalAlignment(JLabel.RIGHT);
        optionPanel.add(label, "w 65!");
        optionPanel.add(new JSeparator(JSeparator.VERTICAL), "spany 5, growy, w 2!");
        optionPanel.add(new JComboBox(new String[] {"option1", "option2", "option3"}), "span, growx, wrap");
  
        optionPanel.add(new JLabel("Type"), "right");
        optionPanel.add(new JTextField("3"), "w 65!, split 2");
        optionPanel.add(new JLabel("Unit"), "wrap");
  
        optionPanel.add(new JLabel("Slide"), "right");
        optionPanel.add(new JSlider(0, 100), "span, growx, wrap");
      }
      return optionPanel;
    }
  
    protected JTabbedPane getRightPanel() {
      if (plotTabPane == null) {
        plotTabPane = new JTabbedPane();
        plotTabPane.add("Tab1", new JPanel());
        plotTabPane.add("Tab2", new JPanel());
      }
      return plotTabPane;
    }
  
    protected JPanel getMessagePanel() {
      if (messagePanel == null) {
        messagePanel = new JPanel();
        messagePanel.setBorder(BorderFactory.createTitledBorder(null, "Status Console", TitledBorder.LEFT, TitledBorder.TOP, new Font("null", Font.BOLD, 12), Color.BLUE));
        messagePanel.setLayout(new MigLayout("insets 0", "", "top, align 50%"));
        messagePanel.add(new JScrollPane(getMessageTextArea()), "push, grow");
      }
      return messagePanel;
    }
  
    protected JTextArea getMessageTextArea() {
      if (messageTextArea == null) {
        messageTextArea = new JTextArea();
        messageTextArea.setEditable(false);
        messageTextArea.setFont(new Font(null, Font.PLAIN, 20));
        messageTextArea.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
      }
      return messageTextArea;
    }
  
    public void printRawMessage(String rawMessage) {
      getMessageTextArea().append(rawMessage);
      getMessageTextArea().setCaretPosition(getMessageTextArea().getText().length());
    }
  }
  </code></pre>
  
  <p>The layout stuff basically happens in <code>initComponents()</code>.</p>
  
  <p><strong>To see the problem:</strong></p>
  
  <ol>
  <li>Start the Application (I used miglayout-4.0-swing.jar).</li>
  <li>Wait a bit (don't resize the window), until there are enough messages to create the scrollbar in the status text area.</li>
  <li>Now this is what I want. The <code>JTextArea</code> goes all the way to the bottom of the JFrame and is scrolled if neccessary.</li>
  <li>Now resize the window. As you can see, everything gets messed up. It will only be fine, if the window is maximized.</li>
  </ol>
  
  <p>Here are two screenshots. The first one is how I want it to be:
  <img src="https://i.stack.imgur.com/99E5p.png" alt="Before resizing: good!">
  The second one is after resizing:
  <img src="https://i.stack.imgur.com/cOekP.png" alt="After resizing: bad!"></p>
  
  <p><strong>My question:</strong> Can somebody tell me, how I keep the layout the way it is before resizing? I want to have the <code>JTextArea</code> go all the way down to the bottom of the window. And if neccessary, the scrollbar should appear. The only way, the status panel can go below the bottom of the window is, if the window is too small (because the configuration panel has a fixed height).</p>
  
  <p>I hope I made myself clear. If not, please ask. ;)</p>
  
  <p>EDIT: You can see the behaviour I want, if you remove the top JScrollPanel (the one that holds all the components). Just change </p>
  
  <pre><code>JScrollPane contentScrollPane = new JScrollPane(mainPanel);
  contentScrollPane.setBorder(BorderFactory.createEmptyBorder());
  setContentPane(contentScrollPane);
  </code></pre>
  
  <p>to </p>
  
  <pre><code>setContentPane(mainPanel);
  </code></pre>
  
  <p>to see what I mean. Unfortunately, this way I loose the scrollbars if the window is very small.</p>