Message Dialog - Jtable

0

First I select two rows or more of a JTable and when I record those selected rows, I get several messages "" The Document "+ doc +" was requested correctly "", (doc is the name of the document), and so on the documents that have been recorded continue to come out, as it would do so that only a confirmation message appears saying that the documents (That the names of the documents that have been selected and recorded in the message come out) have been recorded successfully. I share the code that I am using:

protected void btnEnviarActionPerformed(ActionEvent arg0) {
        //se crea una variable para que contenga la fila seleccionada de la tabla
        int[] selectedRow = tbDocTransferir.getSelectedRows();
        int i = tbDocTransferir.getSelectedRow();
        //hacemos una condicion de que si la varialbe i es -1 es que no se ha seleccionado ninguna 
        //fila
        if (i == -1){
            JOptionPane.showMessageDialog(null,"Seleccione la fila que desea solicitar"); 
        }
        else{
            for (int t : selectedRow){
            String codArchivo = (String) tbDocTransferir.getValueAt(t, 0);
            String codCentroCosto = (String) tbDocTransferir.getValueAt(t, 1);
            String tipoArchivo = (String) tbDocTransferir.getValueAt(t, 4);
            String doc = (String) tbDocTransferir.getValueAt(t, 6);
            String nivelArchivo = (String) tbDocTransferir.getValueAt(t, 8);
            String lote = (String) tbDocTransferir.getValueAt(t, 10);
            String fila = (String) tbDocTransferir.getValueAt(t, 11);
            String usuarioSolicita = Constante.idUsuario;
            String fechaSolicita = txtFechaSolicita.getText();
            Objeto object = (Objeto) cboCentroCostoDestino.getSelectedItem();
            String centroCostoDestino = ((Objeto)object).getCodigo();
            String centroCostoOrigen = Constante.c_ccosto;
            MovimientoArchivoDTO x = new MovimientoArchivoDTO();
            x.setC_c_archivo(codArchivo);
            CentroCostoDTO c = new CentroCostoDTO();
            c.setC_ccosto(codCentroCosto);
            c.setC_ccosto(centroCostoOrigen);
            x.setC_ccosto(c);
            x.setC_ccosto_origen(c);
            x.setC_ccosto_destino(centroCostoDestino);
            x.setC_tipo_doc(tipoArchivo);
            x.setC_t_doc(doc);
            x.setC_c_nivel_archivo(nivelArchivo);
            x.setLote(lote);
            x.setFila(fila);
            x.setC_c_usuario_solicita(usuarioSolicita);
            x.setD_dt_solicita(fechaSolicita);
            int estado = xy.RegistrarSolicitudArchivo_SA(x);
            if (estado == 1){
                mensaje("El Documento "+doc+" se solicitó correctamente");
//              ListarDocumento(Constante.c_ccosto, Integer.parseInt(txtFlgEnvia_0.getText()));
                lblDestinoDelDocumento.setVisible(false);
                cboCentroCostoDestino.setVisible(false);
//              cboCentroCostoDestino.setSelectedIndex(0);
            }
            else
                mensaje("Error en enviar");
            }
        }
    }

    void mensaje(String m){
        JOptionPane.showMessageDialog(null, m);
    }
    
asked by Bruno 01.02.2017 в 18:17
source

2 answers

0

Create a variable outside the method where you store the concatenated text,

then within the form concatenate the values of doc to the variable concatenated_text

Finally out of the form you use the JOptionPane to show the final text. The idea is this:

    public static void main(String[] args) {
    String docs = "documentos solicitados\n";

    //este sería tu for
    for (int i = 0; i < 10; i++) {
        //aqui concatenas, en vez de i sera el valor de doc
        docs += i + "\n";
    }
    //finalmente fuera del for muestras el mensaje
    JOptionPane.showMessageDialog(null,docs);

}
    
answered by 01.02.2017 в 18:22
0

The moment you show it on the screen, add it to an array of Strings, and then in the Dialog using a for concatenation and samples.

Something like this:

String[] docs = new String[selectedRows.lengh];
//aqui tu for
for(int t : selectedRows){
    ... tu código ...
    mensaje(doc);
    docs[t] = doc;
}
//fin del for
String mensaje = "";
for (int indice : docs){
     mensaje += "Documento número "+(indice+1)+": "+docs[indice] + ".\n"
}
JOptionPane.showMessageDialog(null,mensaje);
    
answered by 02.02.2017 в 00:00