import javax.swing.*;
import java.awt.*;public class Test { /**
 * @param args
 */
public static void main(String[] args) {
// TODO Auto-generated method stub
new TestFrame();
}}class TestFrame extends JFrame
{
/**
 * 
 */
private static final long serialVersionUID = -8293241744980996488L; public TestFrame()
{
JPanel p = (JPanel)this.getContentPane();
p.add(new JScrollPane(new TestPanel()));
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(200, 600);
this.setVisible(true);
}
}class TestPanel extends JPanel
{
/**
 * 
 */
private static final long serialVersionUID = 740517326400324928L;
JLabel[] lbl = new JLabel[50];
JLabel[] lbl2 = new JLabel[50];
JLabel[] lbl3 = new JLabel[50];
public TestPanel()
{
this.setLayout(null);
for (int i = 0; i < 50; i++)
{
lbl[i] = new JLabel();
lbl[i].setOpaque(true);
lbl[i].setBorder(BorderFactory.createLineBorder(Color.blue));
lbl[i].setSize(20, 50);
lbl[i].setLocation(4, 50 * i + 2);
lbl2[i] = new JLabel();
lbl2[i].setOpaque(true);
lbl2[i].setBorder(BorderFactory.createLineBorder(Color.RED));
lbl2[i].setSize(50, 50);
lbl2[i].setLocation(28, 50 * i + 4);
lbl3[i] = new JLabel();
lbl3[i].setOpaque(true);
lbl3[i].setBorder(BorderFactory.createLineBorder(Color.yellow));
lbl3[i].setSize(50, 20);
lbl3[i].setLocation(84, 50 * i + 20);
this.add(lbl[i]);
this.add(lbl2[i]);
this.add(lbl3[i]);
}
this.setSize(130, 50 * 50 + 50 * 2);
}
}
怎么让滚动条出来?