Java - Mostrar el registro de mi JComboBox cuando selecciono una fila de un JTable java

 
Vista:

Mostrar el registro de mi JComboBox cuando selecciono una fila de un JTable java

Publicado por alejandro (1 intervención) el 21/04/2019 01:53:49
lo que quiero es que al seleccionar una fila de la tabla me aparezca en mi combobox, resulta con las cajas de texto pero con los combobox no me hala el registro guardado.

este es mi codigo de la tabla

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
private void tablalistadopedidoMouseClicked(java.awt.event.MouseEvent evt) {
 
    int fila = tablalistadopedido.rowAtPoint(evt.getPoint());
    txtidentrada.setText(tablalistadopedido.getValueAt(fila, 0).toString());
    txtfacturapedido.setText(tablalistadopedido.getValueAt(fila, 1).toString());
    fechapedido.setDate(Date.valueOf(tablalistadopedido.getValueAt(fila, 2).toString()));
    txtidproveedorpedido.setText(tablalistadopedido.getValueAt(fila, 3).toString());
    txtnombreproveedorpedido1.setText(tablalistadopedido.getValueAt(fila, 4).toString());
    txtidmaterialpedido.setText(tablalistadopedido.getValueAt(fila, 5).toString());
    txtmaterialpedido.setText(tablalistadopedido.getValueAt(fila, 6).toString());
    txtidUnidad.setText(tablalistadopedido.getValueAt(fila, 7).toString());
    cbxunidadM.setSelectedItem(String.valueOf(tablalistadopedido.getValueAt(fila, 8)));
    txtcantidadproducto.setText(tablalistadopedido.getValueAt(fila, 9).toString());
    txtprecioproducto.setText(tablalistadopedido.getValueAt(fila, 10).toString());
 
}

este es el que selecciono el combobox

1
2
3
4
5
6
7
8
9
private void cbxunidadMItemStateChanged(java.awt.event.ItemEvent evt) {
    SQLpedido SQLped = new SQLpedido();
    pedido ped = new pedido();
    if (evt.getStateChange() == ItemEvent.SELECTED) {
        unidad_Medida unm = (unidad_Medida) cbxunidadM.getSelectedItem();
        this.txtidUnidad.setText(String.valueOf(unm.getId()));
 
    }
}


y esta es mi clase de unidad de medida

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
public class unidad_Medida {
 
    private int id;
    private String nombre;
 
    public int getId() {
        return id;
    }
 
    public void setId(int id) {
        this.id = id;
    }
 
    public String getNombre() {
        return nombre;
    }
 
    public void setNombre(String nombre) {
        this.nombre = nombre;
    }
 
    public String toString() {
        return this.nombre;
    }
 
    public Vector<unidad_Medida> mostrarDatos() {
 
        PreparedStatement ps = null;
        ResultSet rs = null;
        conexion con = new conexion();
        Connection conn = con.conectar();
 
        Vector<unidad_Medida> datos = new Vector<unidad_Medida>();
 
        unidad_Medida um = null;
        try {
 
            String sql = "SELECT * FROM unidad_medida order by descripcion";
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
            um = new unidad_Medida();
            um.setId(0);
            um.setNombre("Seleccione..");
            datos.add(um);
 
            while (rs.next()) {
                um = new unidad_Medida();
                um.setId(rs.getInt("idunidad_medida"));
                um.setNombre(rs.getString("descripcion"));
                datos.add(um);
            }
 
        } catch (Exception e) {
        }
             return datos;
    }
 
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder