使用JScrollPane的问题,纵向的滚动条出不来?
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);
}
}