【发布时间】:2012-04-14 18:27:06
【问题描述】:
我使用下面的编码使用另一个 jcombobox 向 jcombobox 添加值,我需要根据在 jcombobox1 中选择的值将值添加到 jcombobox2 而不附加值所以有人可以告诉我重置或清除的方法选择另一个选项时的组合框值? 下面是我的编码,我是 java 和 netbeans 的新手,所以如果有人可以帮助我将不胜感激:)
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/database1", "root", "senura123");
Statement stat = (Statement) con.createStatement();
String val=jComboBox1.getSelectedItem().toString();
String check; String col;
if ("Vehicles".equals(val)){
check = "select reg_no from vehicle;";
col="reg_no";
}
else if ("Travel Guides".equals(val)){
check = "select username from travelguide;";
col="username";
}
else{
check = "select username from transportofficer";
col="username";
}
ResultSet rslt = stat.executeQuery(check);
while (rslt.next()) {
jComboBox2.addItem(rslt.getString(col));
}
}
【问题讨论】:
标签: java swing reset jcombobox