0

Is there a way to copy selected columns from a single table and add it to another Jtable? The way I'm trying to do this is to have the add and remove buttons left of the second table to add the selected columns from the above table and remove button to remove those columns I initially added. I'm new and currently learning how to use JavaSwing, but I'm unsure how I would implement this.

private void RemoveColBActionPerformed(java.awt.event.ActionEvent evt) {                                           
        // Removes the column copied :
        DefaultTableModel model2 =(DefaultTableModel) CopiedTables.getModel(); // New Table
    }                                          
private void AddBActionPerformed(java.awt.event.ActionEvent evt) {                                     
//Add Data
lMessage.setText("");
DefaultTableModel model =(DefaultTableModel) JtableData.getModel();
if(!ProdNameTF.getText().trim().equals("")) {


model.addRow(new Object []{ProdNameTF.getText(), CategoryCB.getSelectedItem().toString(), PriceTF.getText()});

} else {

            lMessage.setText("Message Left Blank");
}
}                                    

private void AddColBActionPerformed(java.awt.event.ActionEvent evt) {                                        
    // Adds the column copied
    DefaultTableModel model =(DefaultTableModel) JtableData.getModel(); //Old Table
    DefaultTableModel model2 =(DefaultTableModel) CopiedTables.getModel(); // New Table
}              

enter image description here

dabrams493
  • 61
  • 6
  • http://stackoverflow.com/questions/3549206/how-to-add-row-in-jtable and use getValueAt(int row, int column) . – Madhawa Priyashantha Mar 13 '16 at 08:11
  • This just adds the rows to the table which I already implemented for the top table with the text fields and combo box. What I'm trying to do is take the highlighted data selected from the top table and move it to the bottom table using the Add and Remove buttons next to it. – dabrams493 Mar 13 '16 at 16:47
  • almost same .retrieve and append . – Madhawa Priyashantha Mar 13 '16 at 17:40

0 Answers0