title: setting the size of a JPanel
body: <p>I have a class that extends a <a href="http://docs.oracle.com/javase/7/docs/api/javax/swing/JPanel.html" rel="nofollow">JPanel</a> called Row. I have a bunch of Row added to a <a href="http://docs.oracle.com/javase/7/docs/api/javax/swing/JLabel.html" rel="nofollow">JLabel</a>, the code is the following:</p>
  
  <pre><code>JFrame f=new JFrame();
  
  JPanel rowPanel = new JPanel();
  //southReviewPanel.setPreferredSize(new Dimension(400,130));
  rowPanel.setLayout(new BoxLayout(rowPanel, BoxLayout.Y_AXIS));
  rowPanel.add(test1);
  rowPanel.add(test1);
  rowPanel.add(test2);
  rowPanel.add(test3);
  rowPanel.add(test4);
  rowPanel.setPreferredSize(new Dimension(600, 400));
  rowPanel.setMaximumSize(rowPanel.getPreferredSize()); 
  rowPanel.setMinimumSize(rowPanel.getPreferredSize());
  
  f.setSize(new Dimension(300,600));
  
  JScrollPane sp = new JScrollPane(rowPanel);
  sp.setSize(new Dimension(300,600));
  f.add(sp);
  
  f.setVisible(true);
  </code></pre>
  
  <p>where test1...etc is a Row. However when I resize the window the layout of the Row somehow becomes messy (it resizes as well)... how can I prevent this from happening?</p>