How to pass a JTable to another JTable by omitting the last two Columns? [closed]

0

I try to pass a JTable1 to JTable2, however I do not want the last 2 columns of the JTable1 to be passed. Thank you in advance !!!

    
asked by Summer 01.08.2018 в 18:12
source

1 answer

0

You could copy the values cell by cell, only from the columns that interest you. Ex: JTable1

     |col1 |col2 |col3 |col4|
     |1    |2    |3    |4   |
     |5    |6    |7    |8   |

JTable 2 would be:

                  |col1 |col2 |
                  |1    |2    |
                  |5    |6    |

And the code would be:

for(int i=0; i<jTable1.getRowCount(); i++){
    Object fila[] = new Object[2];
    DefaultTableModel modelo = (DefaultTableModel) jTable2.getModel();
    fila[0] = String.valueOf(jTable1.getValueAt(i, 0);
    fila[1] = String.valueOf(jTable1.getValueAt(i, 1);
    modelo.addRow(fila);
}

I do not know if that helps you to copy them, if I did not understand well I wait for your answer to try to help you! Greetings!

    
answered by 01.08.2018 / 20:51
source