我有一个 JList 需要放置在滚动窗格中,因为我从数据库中获取 JList 并且值可以大大增加。我需要能够向下滚动它们,所以我写道:
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
public class Checkboxlistener extends JFrame {
private JPanel jpAcc = new JPanel();
private JList checkBoxesJList;
Checkboxlistener() {
// super("Deposit base", false, true, false, true);
setSize(1300, 600);
jpAcc.setLayout(null);
jpAcc.setBackground(Color.LIGHT_GRAY);
String labels[] = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J"};
checkBoxesJList = new JList(labels);
checkBoxesJList.setBounds(10, 30, 80, 600);
checkBoxesJList.setBackground(Color.LIGHT_GRAY);
checkBoxesJList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
JScrollPane scrollPane = new JScrollPane(checkBoxesJList);
jpAcc.add(checkBoxesJList);
jpAcc.add(scrollPane);
getContentPane().add(jpAcc);
setVisible(true);
}
public static void main(String args[]) {
Checkboxlistener cbl = new Checkboxlistener();
}
}
我做错了什么,因为我没有看到任何 ScrollPane?