title: resize child panel when resizing parent JFrame
body: <p>I have a <code>JFrame</code> which contains a <code>JPanel</code>. The frame can be resized by the user using the mouse. When the width of the frame is > 400, the jpanel inside's width is set to 10; otherwise 1080.</p>
  
  <p>In between the frame and the panel, there is also a <code>JScrollBar</code>.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>import java.awt.BorderLayout;
  import java.awt.Color;
  import java.awt.Dimension;
  import java.awt.event.ComponentEvent;
  import javax.swing.*;
  import javax.swing.table.*;
  /**
   *
   * @author Administrator
   */
  public class TableFrame extends javax.swing.JFrame {
  public JScrollPane jScrollPane1 = new JScrollPane();
  public JTable table;
  public JScrollPane getScrollPane(){
      return this.jScrollPane1;
  }
  
  JPanel inFrame = new JPanel();
  public TableFrame() {
      initComponents();
  
      jScrollPane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
      jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
      //this.jScrollPane1.setViewportView(inFrame);
      this.getContentPane().setLayout(new BorderLayout());
      this.addComponentListener(new java.awt.event.ComponentAdapter() {
          public void componentResized(ComponentEvent e) {
                      setSize();
              }
      });
      this.getContentPane().add(this.jScrollPane1);
  
      this.jScrollPane1.setViewportView(this.inFrame);
  
  }
  
  public void setSize(){
      int w = this.getWidth();
      int width = 0;
      int height = 1000;
      if(w &lt; 400){
          width = 10;
          this.inFrame.setBackground(Color.blue);
      }else{
          width = 1080;
          this.inFrame.setBackground(Color.red);
      }
      this.inFrame.setPreferredSize(new Dimension(width, height));
      this.jScrollPane1.revalidate();
  }
  
  /** This method is called from within the constructor to
   * initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is
   * always regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // &lt;editor-fold defaultstate="collapsed" desc="Generated Code"&gt;
  private void initComponents() {
  
      setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  
      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
      getContentPane().setLayout(layout);
      layout.setHorizontalGroup(
          layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGap(0, 400, Short.MAX_VALUE)
      );
      layout.setVerticalGroup(
          layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGap(0, 300, Short.MAX_VALUE)
      );
  
      pack();
  }// &lt;/editor-fold&gt;
  
  /**
  * @param args the command line arguments
  */
  public static void main(String args[]) {
      TableFrame frame = new TableFrame();
  
      frame.setVisible(true);
  
  
  }
  
  // Variables declaration - do not modify
  // End of variables declaration
  </code></pre>
  
  <p>}</p>
  
  <p>However, the <code>JScrollPane</code>'s scrollbar doesn't work as expectedly. When I resize the frame from width great than 400 to less than 400, the scrollbar does not update correctly. What I need is that when the frame's width is smaller than a threshold, the panel should resize to a constant value, otherwise another value.</p>