Pass data from JTable to Jtable with saved auto

0

Good friends, I present a problem in my code, the question would be: How do I make it so that when passing data from one table to another, those that were already there are not deleted?

I am passing a selected row from a JTablePendientes to another JTableCompletados in the same Frame through a simple button, these tables are automatically saved in Excel files with the jxl library. In itself I think the problem lies more in that when you restart the application and re-pass data through the button, they are inserted in the first row of the other table, deleting the data that were already.

Here is a bit of code:

This is the Action Listener that passes the row of JTablePendientes to JTable Completed:

menuItemCompletar.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if(tablaListado.getSelectedRowCount() > 0) {
                 // 1) Obtener los índices de las filas seleccionadas.
                 int[] indices = tablaListado.getSelectedRows();
                 // 2) Para cada fila, crear un Array para guardar los valores. 
                 for(int i : indices) {
                     Object[] fila = new Object[modelo.getColumnCount()];
                     // Guardar los valores de la fila de origen.
                     for(int j = 0; j < fila.length; j++) {
                         fila[j] = modelo.getValueAt(i, j);
                     }
                     // 3) Agregar la fila al TableModel de la tabla de destino
                     modelo2.addRow(fila);
                 }
                 autoGuardado();
             }

This would be the code that saves the tables to an Excel file:

public void autoGuardado() {

        try {
            List<JTable> tb = new ArrayList<JTable>();
            tb.add(JTablePendientes);
            //-------------------
            export_excel excelExporter = new export_excel(tb, new File(EXCEL_FILE_LOCATION));
            excelExporter.export();  // Ejecuta el auto guardado
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        try {
            List<JTable> tb2 = new ArrayList<JTable>();
            tb2.add(JTableCompletos);
            //-------------------
            export_excel excelExporter2 = new export_excel(tb2, new File(EXCEL_FILE_LOCATION2));
            excelExporter2.export();  // Ejecuta el auto guardado
        } catch (Exception ex) {
            ex.printStackTrace();
        }

}

As you can see in the images the rows are passed correctly, but when you restart the application and "Complete" other rows, they are deleted.

Any advice?

    
asked by vicc skor 14.09.2017 в 20:39
source

0 answers