即时通讯使用下面的编码使用另一个jcombobox将值添加到jcombobox,我需要根据在jcombobox1中选择的一个获取值添加值到jcombobox2,而不追加值,所以有人可以告诉我选择另一个选项时重置或清除组合框值的方法?下面 是我的编码,我是新来的Java和NetBeans因此,如果有人能帮我会感激:)重置/清除jcombobox值需要帮助
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));
}
}
感谢您的参考!它的工作! :) – senrulz 2012-04-16 11:11:19
非常有帮助。谢谢! – aaiezza 2015-04-17 04:13:37