请看下面的小代码。滚动窗格出现了,但是滑块没有出现。即使我重新调整了窗口大小,滑块也没有出现。请帮忙解决。
import javax.swing.*;
public class sample {
static JFrame frame;
public static void main(String[] args) {
String Msg = "Sample Message To Test Scrolling";
frame = new JFrame("Sample Program");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600, 600);
JPanel panel = new JPanel();
panel.setLayout(null);
for (int ypos = 0, i = 0; i < 40; i++) {
JLabel label = new JLabel("" + i + " " + Msg);
label.setFont(new Font("Courier", Font.BOLD, 12));
panel.add(label);
label.setBounds(10, ypos + 5,
label.getPreferredSize().width,
label.getPreferredSize().height);
ypos += label.getPreferredSize().height;
}
JScrollPane scroll = new JScrollPane(panel,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
frame.setLayout(new BorderLayput());
frame.add(scroll);
frame.setVisible(true);
}
}