Bind jComboBox
public class
KeyValue {
private String value;
KeyValue () {
}
KeyValue (Object key, String value) {
this.key=key;
this.value=value;
}
public Object getKey() {
return this.key;
}
public void setKey(Object key) {
this.key=key;
}
public String getValue() {
return this.value;
}
public void setValue(String value) {
this.value=value;
}
@Override
public String toString() {
return this.value;
}
}
public void
bindComboBox()
{
Connection connection;
try {
MainClass mc=new MainClass();
connection=DriverManager.getConnection(mc.StrUrl,mc.StrUid,mc.StrPwd);
ResultSet rs;
PreparedStatement
stmt=connection.prepareStatement("select Id, user_name, user_password,
user_type from lib_user");
rs = stmt.executeQuery();
while(rs.next()){
String name =rs.getString("user_name");
String
Id=rs.getString("Id");
// jComboBox1.addItem(name);
jComboBox1.addItem(new
KeyValue(rs.getString("Id"),rs.getString("user_name")));
//
jComboBox1.setPrototypeDisplayValue("user_name");
//
jComboBox1.getSelectedItem().toString());
}
} catch (Exception e) {
System.err.println(e);
//System.exit(1);
}
finally {
}
}
No comments:
Post a Comment