解决方案
JScrollPane scrollPane = new JScrollPane();
listModel = new DefaultListModel<String>();
JList list = new JList<String>(listModel);
//用这句代码
scrollPane.setViewportView(list);
错误示例
JScrollPane scrollPane = new JScrollPane();
listModel = new DefaultListModel<String>();
JList list = new JList<String>(listModel);
//错误示例
scrollPane.add(list);