title: How can I stop my Swing program from resizing components every time I add text to my JTextArea
body: <p>I have a Swing application with a JTextArea at the bottom of the frame, which spans the whole width and when a user makes a mistake an error message is displayed in the JTextArea. Although  when this happens the two columns on the right hand side become wider and the two on the left become narrower. I have searched everywhere and can't find a way to stop this happening. Please can someone explain a way for me to fix this? The code for my GUI is shown below.</p>
  
  <pre><code>public GUI(Event event) {
          super("Checkpoint Manager");
          this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          setResizable(false);
          setLocation(165,25);
          listener = new Listener(event, this);
  
          // Initializes labels and text fields.
          arrivalLabel = new JLabel("Arrival Time:  ");
          depLabel = new JLabel("Departure Time:  ");
          checkLabel = new JLabel("Tick For Exclusion:  ");
          SimpleDateFormat format = new SimpleDateFormat("HH:mm");
          arrival = new JFormattedTextField(format);
          dep = new JFormattedTextField(format);
          check = new JCheckBox();
  
          // Initializes panel and buttons, also adds ActionListeners to buttons.
          panel = new JPanel();
          panel.setLayout(new GridBagLayout());
          setLayout(new FlowLayout());
          submit = new JButton("Submit");
          cancel = new JButton("Cancel");
          enterMed = new JButton("Enter Medical Checkpoint");
          enterTime = new JButton("Enter Time Checkpoint");
          submit.addActionListener(listener);
          cancel.addActionListener(listener);
          enterMed.addActionListener(listener);
          enterTime.addActionListener(listener);
  
          // Initializes the messageArea and sets the border for it.
          messageArea = new JTextArea();
          messageArea.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createCompoundBorder
                  (BorderFactory.createTitledBorder("Messages"),BorderFactory.createEmptyBorder(5,5,5,5)),messageArea.getBorder()));
  
  
          // Initializes the ScrollPane for the timeList and adds the timeList to it. 
          entrantModel = new DefaultListModel();
          entrantList = new JList(entrantModel);
          entrantList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
          entrantPane = new JScrollPane(entrantList);
          entrantPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createCompoundBorder
          (BorderFactory.createTitledBorder("Entrants"),BorderFactory.createEmptyBorder(5,5,5,5)),entrantPane.getBorder()));
          entrantPane.setMaximumSize(new Dimension(60,300));
          // Initializes the ScrollPane for the timeList and adds the timeList to it. 
          nodeModel = new DefaultListModel();
          nodeList = new JList(nodeModel);
          nodeList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
          nodePane = new JScrollPane(nodeList);
          nodePane.setMaximumSize(new Dimension(60, 300));
          nodePane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createCompoundBorder
          (BorderFactory.createTitledBorder("Nodes"),BorderFactory.createEmptyBorder(5,5,5,5)),nodePane.getBorder()));
  
  
          // Structures the components in the frame using GridBagLayout.
          GridBagConstraints c = new GridBagConstraints();
          c.gridx = 0;
          c.gridy = 0;
          c.gridwidth = 2;
          c.ipadx = 5;
          c.insets = new Insets(10,10,10,10);
          c.fill = GridBagConstraints.HORIZONTAL;
          panel.add(enterTime, c);
  
          c.gridx = 2;
          c.gridy = 0;
          c.gridwidth = 2;
          c.ipadx = 5;
          c.insets = new Insets(10,10,10,10);
          c.fill = GridBagConstraints.HORIZONTAL;
          panel.add(enterMed, c);
  
          c.gridx = 0;
          c.gridy = 1;
          c.gridwidth = 2;
          c.ipady = 100;
          c.insets = new Insets(10,10,10,10);
          c.fill = GridBagConstraints.HORIZONTAL;
          panel.add(entrantPane, c);
  
          c.gridx = 2;
          c.gridy = 1;
          c.gridwidth = 2;
          c.ipady = 100;
          c.insets = new Insets(10,10,10,10);
          c.fill = GridBagConstraints.HORIZONTAL;
          panel.add(nodePane, c);
  
          c.gridx = 0;
          c.gridy = 2;
          c.gridwidth = 1;
          c.ipadx = 5;
          c.ipady = 5;
          c.insets = new Insets(10,10,10,10);
          c.fill = GridBagConstraints.HORIZONTAL;
          panel.add(arrivalLabel, c);
  
          c.gridx = 1;
          c.gridy = 2;
          c.gridwidth = 1;
          c.ipadx = 5;
          c.ipady = 5;
          c.insets = new Insets(10,10,10,10);
          c.fill = GridBagConstraints.HORIZONTAL;
          panel.add(arrival, c);
  
          c.gridx = 2;
          c.gridy = 2;
          c.gridwidth = 1;
          c.ipadx = 5;
          c.ipady = 5;
          c.insets = new Insets(10,10,10,10);
          c.fill = GridBagConstraints.HORIZONTAL;
          panel.add(checkLabel, c);
  
          c.gridx = 3;
          c.gridy = 2;
          c.gridwidth = 1;
          c.ipadx = 5;
          c.ipady = 5;
          c.insets = new Insets(10,10,10,10);
          c.fill = GridBagConstraints.HORIZONTAL;
          panel.add(check, c);
  
          c.gridx = 0;
          c.gridy = 3;
          c.gridwidth = 1;
          c.ipadx = 5;
          c.ipady = 5;
          c.insets = new Insets(10,10,10,10);
          c.fill = GridBagConstraints.HORIZONTAL;
          panel.add(depLabel, c);
  
          c.gridx = 1;
          c.gridy = 3;
          c.gridwidth = 1;
          c.ipadx = 5;
          c.ipady = 5;
          c.insets = new Insets(10,10,10,10);
          c.fill = GridBagConstraints.HORIZONTAL;
          panel.add(dep, c);
  
          c.gridx = 2;
          c.gridy = 3;
          c.gridwidth = 1;
          c.ipadx = 5;
          c.ipady = 5;
          c.insets = new Insets(10,10,10,10);
          c.fill = GridBagConstraints.HORIZONTAL;
          panel.add(submit, c);
  
          c.gridx = 3;
          c.gridy = 3;
          c.gridwidth = 1;
          c.ipadx = 5;
          c.ipady = 5;
          c.insets = new Insets(10,10,10,10);
          c.fill = GridBagConstraints.HORIZONTAL;
          panel.add(cancel, c);
  
          c.gridx = 0;
          c.gridy = 4;
          c.gridwidth = 4;
          c.ipadx = 20;
          c.ipady = 30;
          c.insets = new Insets(10,10,10,10);
          c.fill = GridBagConstraints.HORIZONTAL;
          panel.add(messageArea, c);
  
          //Adds the panel to the frame and sets the components to fit according to the size of the frame. 
          add(panel, c);
  
          pack(); 
          setVisible(true);
      }
  </code></pre>