title: Can I increase the size of a JPanel?
body: <p>I have some code here, and when the button is pressed, I'm trying to extend the JPanel. However, it remains at the height it was previously. Is there a way to do this or is it fixed on the dimensions it was set when it was created?</p>
  
  <pre><code>public class GUITest extends JFrame {
  
      JPanel jp;
      JButton one;
  
      public static void main(String[] args) {
          new GUITest();
      }
  
      public GUITest() {
          initWidgets();
      }
  
      public void initWidgets() {
          setSize(250, 250);
          setTitle("Stretch Panel Example");
          setDefaultCloseOperation(EXIT_ON_CLOSE);
          setLayout(new FlowLayout());
          one = new JButton("Click me!");
          ActionListener extend = new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent e) {
                  for (int i = 0; i &lt; 80; i++) {
                      jp.setPreferredSize(new Dimension(200,(i+70)));
                  }
                  //System.out.println(jp.getHeight());
              }
          };
          one.addActionListener(extend);
          add(one, BorderLayout.NORTH);
          jp = new JPanel();
          jp.setBackground(Color.BLACK);
          jp.setPreferredSize(new Dimension(200,70));
          add(jp, BorderLayout.CENTER);
          setVisible(true);
      }
  
  }
  </code></pre>