import javax.swing.*;
import java.awt.*;public class TestFlowLayout
    extends JFrame {
  JScrollPane jScrollPane1 = new JScrollPane();
  JPanel jPanel1 = new JPanel();
  FlowLayout flowLayout1 = new FlowLayout();
  BorderLayout borderLayout1 = new BorderLayout();  public TestFlowLayout() {
    try {
      this.setSize(400, 300);
      jbInit();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }  private void jbInit() throws Exception {
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    this.getContentPane().setLayout(borderLayout1);
    jPanel1.setLayout(flowLayout1);
    flowLayout1.setAlignment(FlowLayout.LEFT);
    for (int i = 9; i < 69; i++) {
      jPanel1.add(new JButton("JButton" + (i + 1)), null);
    }
    jPanel1.setPreferredSize(new Dimension(380, -1));
    this.getContentPane().add(jScrollPane1, BorderLayout.CENTER);
    jScrollPane1.getViewport().add(jPanel1, null);
  }  public static void main(String[] args) {
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    }
    catch (Exception e) {
      e.printStackTrace();
    }
    TestFlowLayout frame = new TestFlowLayout();
    frame.setVisible(true);
  }}

解决方案 »

  1.   

    加上这一句,jScrollPane1.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);添加横向的滚动条方法同上。
      

  2.   

    jPanel1.setPreferredSize(new Dimension(380, -1));
    改为jPanel1.setPreferredSize(new Dimension(380, 380));就OK了
      

  3.   

    to:autowind(一个人住真痛苦) 
       jScrollPane1.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);纵向的滚动条是有了,但不能滚动。jPanel1的内容也还是看不到。to:hemiao_1993(冷血动物) 
       jPanel1.setPreferredSize(new Dimension(380, 380));后是能滚动了,但jPanel1的内容是动态的,这样好象不行的。总之还是要谢谢二位。
      

  4.   

    测了下.
    this.setSize(400, 300);
    上面这句设置了300
    下面的话不能小于265,低于这个数字好象就不行了.