我想知道是否有办法在带有JPanel的JFrame上添加JList。我正在制作一个程序,我搜索了整个网站的答案,但我找不到答案。无论如何最好带有滚动窗格的JList(如果可能的话)(
)这是我的代码:
public static void main(String args[]) {
JScrollPane scrollpane;
JFrame frame = new JFrame();
JList list;
String categories[] = { "1", "2", "3","4", "5", "6", "7","8", "9", "10", "11", "12" };
list = new JList(categories);
JScrollPane scrollpane1 = new JScrollPane(list);
frame.getContentPane().add(scrollpane1, BorderLayout.CENTER);
MyClass sl = new MyClass();
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.setSize(300, 200);
frame.setVisible(true);
}