我再次在显示来自 mysql 数据库的数据时遇到 JList 问题,我使用了下面给出的代码,但它没有在屏幕上显示任何内容..
JFrame f8 = new JFrame("Schedule");
f8.setVisible(true);
f8.setSize(1000, 1000);
JPanel jpa1 = new JPanel(new GridBagLayout());
String query = "SELECT * FROM Location";
DefaultListModel model = new DefaultListModel();
DefaultListModel model1 = new DefaultListModel();
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
Statement stmt = null;
ResultSet rs;
Connection conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1/SPL", "root", "PWD");
stmt = (Statement) conn.createStatement();
rs = stmt.executeQuery(query);
while (rs.next()) {
String stadium = rs.getString("Stadium");
String city = rs.getString("City");
model.addElement(stadium);
model1.addElement(city);
}
JList list = new JList(model);
JList list1 = new JList(model1);
f8.add(jpa1);
jpa1.add(list);
list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
list.setLayoutOrientation(JList.HORIZONTAL_WRAP);
list.setVisibleRowCount(1);
JScrollPane listScroller = new JScrollPane(list);
} catch (SQLException e) {
System.out.println("Message : " + e.getMessage());
}
你能告诉我我哪里错了吗?