title: How to swap value of cell in jtable by drag and drop
body: <p>I would like to swap the data of my table from one table to another IN THE SAME COLUMN (Note: I have only two columns).</p>
  
  <p>My problem is I cannot swap the value. Also, I want the swapping to be enabled only on the same column, otherwise, the table values will reset to its original values.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>    JTable table_1 = new JTable(model);
  table_1.setPreferredScrollableViewportSize(new Dimension(300, 120));
  table_1.setDragEnabled(true);  
  table_1.setDropMode(DropMode.USE_SELECTION);  
  table_1.setTransferHandler(new TransferHelper()); 
  table_1.setRowSelectionAllowed(false);
  table_1.setCellSelectionEnabled(true);
  </code></pre>
  
  <p>My TransferHelper Class:</p>
  
  <pre><code>class TransferHelper extends TransferHandler {  
  
      private static final long serialVersionUID = 1L;
  
      public TransferHelper() {  
      }  
  
      @Override  
      public int getSourceActions(JComponent c) {  
          return MOVE;  
      }  
  
      @Override  
      protected Transferable createTransferable(JComponent source) {  
          String data = (String) ((JTable) source).getModel().getValueAt(((JTable) source).getSelectedRow(), ((JTable) source).getSelectedColumn());
          return new StringSelection(data);  
      }  
  
      @Override  
      protected void exportDone(JComponent source, Transferable data, int action) {  
          ((JTable) source).getModel().setValueAt("", ((JTable) source).getSelectedRow(), ((JTable) source).getSelectedColumn());  
      }  
  
      @Override  
      public boolean canImport(TransferSupport support) {  
          return true;  
      }  
  
      @Override  
      public boolean importData(TransferSupport support) {  
          JTable jt = (JTable) support.getComponent();  
          try {
              jt.setValueAt(support.getTransferable().getTransferData(DataFlavor.stringFlavor), jt.getSelectedRow(), jt.getSelectedColumn());  
          } catch (UnsupportedFlavorException ex) {  
  
          } catch (IOException ex) {  
  
          }  
          return super.importData(support);  
      }  
  }  
  </code></pre>