Java - Problemas en JTable

 
Vista:
sin imagen de perfil
Val: 106
Ha mantenido su posición en Java (en relación al último mes)
Gráfica de Java

Problemas en JTable

Publicado por Hector (63 intervenciones) el 30/03/2019 15:51:14
Hola amigos del foro he aquí de nuevo molestando, les cuento que en la pantalla de presupuestos poseo dos jtable, una para la mano de obra y otra para los repuestos, mi primera consulta es posible tener dos jtable en una sola pantalla, se los muestro en el archivo adjunto.
por otro lado al realizar el proceso de modificar y eliminar en la primera jtable, que corresponde a la man de obra funciona muy bien, les adjunto aquí el código que utilizo:
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
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
    int fila = tblDatos.getSelectedRow();
    if (fila >= 0) {
        txtitem.setText(tblDatos.getValueAt(fila, 0).toString());
        txtmano.setText(tblDatos.getValueAt(fila, 1).toString());
        txtvalor.setText(tblDatos.getValueAt(fila, 2).toString());
        txtpatente.setText(tblDatos.getValueAt(fila, 3).toString());
        txtactivo.setText(tblDatos.getValueAt(fila, 4).toString());
        txtfactura.setText(tblDatos.getValueAt(fila, 5).toString());
        txtboleta.setText(tblDatos.getValueAt(fila, 6).toString());
        modificar.setVisible(true);
    } else {
        JOptionPane.showMessageDialog(null, "no seleciono fila");
    }
}
 
private void modificarActionPerformed(java.awt.event.ActionEvent evt) {
    try {
        PreparedStatement pst = cn.prepareStatement("UPDATE presupuesto1 SET Mano_Mobra='" + txtmano.getText() + "',Valor_Mobra=" + txtvalor.getText() + " WHERE N_Filas=" + txtitem.getText() + "");
        pst.executeUpdate();
        mostrardatos("");
        txtmano.setText("");
        txtvalor.setText("");
        int desicion = JOptionPane.showConfirmDialog(null, "¿Desea seguir modificando?");
        switch (desicion) {
            case JOptionPane.YES_OPTION:
                txtmano.requestFocus();
                break;
            case JOptionPane.NO_OPTION:
                JOptionPane.showMessageDialog(null, "Ud. escogio no seguir modificando");
                SumaMano.requestFocus();
                modificar.setVisible(false);
                break;
            default:
                JOptionPane.showMessageDialog(null, "Ha cancelado la operación");
                txtmano.requestFocus();
                modificar.setVisible(false);
                break;
        }
    } catch (Exception e) {
        System.out.print(e.getMessage());
    }
}
 
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
    int fila = tblDatos.getSelectedRow();
    String cod = "";
    cod = tblDatos.getValueAt(fila, 0).toString();
 
    try {
        PreparedStatement pst = cn.prepareStatement("Delete From presupuesto1 WHERE  N_Filas='" + cod + "'");
        pst.executeUpdate();
        mostrardatos("");
        contar();
    } catch (Exception e) {
 
    }
}

he aquí el código que utilizo para la segunda jtable que ocupo en repuestos:
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
59
60
61
62
private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {
    int fila = tblDatos1.getSelectedRow();
    if (fila >= 0) {
        txtitem1.setText(tblDatos1.getValueAt(fila, 0).toString());
        txtcantidad.setText(tblDatos1.getValueAt(fila, 1).toString());
        txtrepuestos.setText(tblDatos1.getValueAt(fila, 2).toString());
        txtvalorrep.setText(tblDatos1.getValueAt(fila, 3).toString());
        txtoriginal.setText(tblDatos1.getValueAt(fila, 4).toString());
        txtalternativo.setText(tblDatos1.getValueAt(fila, 5).toString());
        txtpatente.setText(tblDatos1.getValueAt(fila, 6).toString());
        txtactivo.setText(tblDatos1.getValueAt(fila, 7).toString());
        txtfactura.setText(tblDatos1.getValueAt(fila, 8).toString());
        txtboleta.setText(tblDatos1.getValueAt(fila, 9).toString());
        modificar1.setVisible(true);
    } else {
        JOptionPane.showMessageDialog(null, "no seleciono fila");
    }
}
 
private void modificar1ActionPerformed(java.awt.event.ActionEvent evt) {
    try {
        PreparedStatement pst = cn.prepareStatement("UPDATE presupuesto2 SET Cant_Repuestos=" + txtcantidad.getText() + ",Repuestos='" + txtrepuestos.getText() + "',Valor_Repuestos=" + txtvalorrep.getText() + " WHERE N_Filas=" + txtitem1.getText() + "");
        pst.executeUpdate();
        mostrardatos1("");
        txtcantidad.setText("");
        txtrepuestos.setText("");
        txtvalorrep.setText("");
        int desicion = JOptionPane.showConfirmDialog(null, "¿Desea seguir modificando?");
        switch (desicion) {
            case JOptionPane.YES_OPTION:
                txtcantidad.requestFocus();
                break;
            case JOptionPane.NO_OPTION:
                JOptionPane.showMessageDialog(null, "Ud. escogio no seguir modificando");
                SumaRep.requestFocus();
                modificar1.setVisible(false);
                break;
            default:
                JOptionPane.showMessageDialog(null, "Ha cancelado la operación");
                txtcantidad.requestFocus();
                modificar1.setVisible(false);
                break;
        }
    } catch (Exception e) {
        System.out.print(e.getMessage());
    }
}
 
private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {
    int fila = tblDatos1.getSelectedRow();
    String cod1 = "";
    cod1 = tblDatos1.getValueAt(fila, 0).toString();
 
    try {
        PreparedStatement pst = cn.prepareStatement("Delete From presupuesto2 WHERE  N_Filas='" + cod1 + "'");
        pst.executeUpdate();
        mostrardatos1("");
        contar1();
    } catch (Exception e) {
 
    }
}
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
este es el error que me da al eliminar una fila de la segunda jtable, no lo se si es el mismo que utilice anteriormente.

favor de ayudarme en solucionar lo de la segunda jtable, si se dan cuenta es el mismo código por ende debería funcionar pro no es así
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