0

I have a program in which I want to use drag and drop. I went through the java drag and drop documentation but I could not really find an answer for this. I want to use the TransferHandler. Basically what I am trying to do is transfer the whole JTextField not only the text inside it so it retains all of it properties. Or in other words the whole object. I saw that you can do a custom DataFlavor.

DataFlavor customFlavor = new DataFlavor(JTextField.class, "JTextField");

I would than probably import data like this:

importData(TransferHandler.TransferSupport supp){
     Transferable t = supp.getTransferable();
     JTextField data = t.getTransferData(customFlavor);
}

The problem I have is how to send the data so I can read it. I am thinking of something like this.

Transferable createTransferable(JComponent c) {
    return new JTextField(); ???
}

How should I transform this to be able to send the JTextField and reconstruct it after the drop.

TenebrisNocte
  • 179
  • 10
  • Just wondering, what specific properties of JTextField are you interested in? – Betlista Feb 13 '18 at 16:12
  • 1
    Here is a [question with JLabel](https://stackoverflow.com/questions/11460704/dragging-a-jlabel-with-a-transferhandler-drag-and-drop), maybe it helps... – Betlista Feb 13 '18 at 16:14
  • @Betlista thanks will certanly take a look at it :) but basically I want to transfer the whole object not just parts of it because I will need it later and I don't want to create a new copy of it – TenebrisNocte Feb 13 '18 at 16:28

0 Answers0