I have the following Form:
What I want you to help me is that when you put a District Id in the text box, in the comboBox you select the district corresponding to the id entered
Here I leave my code
public class daoempleado{
conexion.conecta cone=new conexion.conecta();
CallableStatement cst=null;
ResultSet rs=null;
public DefaultComboBoxModel valorsito(){
DefaultComboBoxModel valor=null;
try {
cst=cone.xconecta().prepareCall("select * from distrito");
rs=cst.executeQuery();
valor=new DefaultComboBoxModel();
while(rs.next())
{
valor.addElement(new beanDistrito(rs.getString(2).trim(),rs.getString(1)));
}
return valor;
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, e.toString());
return null;
}
}
}
-
This is my BeanDistrict class
public class beanDistrito { private String nombre; private String id; public String getId(){ return id; } public String toString(){ return nombre; } public beanDistrito() { } public beanDistrito(String nombre, String id) { this.nombre = nombre; this.id = id; } }
-
Here I call it on my form after the initcomponents
private void ListarDistritos() { cbo1.setModel(d_emp.valorsito()); }
-
In this way
public NewJDialog(java.awt.Frame parent, boolean modal) { super(parent, modal); initComponents(); ListarDistritos(); }