How can I get data from DragSourceDropEvent
I have a JTree and I decide to add a DragSourceListener by createDefaultDragGestureRecognizer, implements the method dragDropEnd,When I drag one node on the tree and drop it in another place ,I can not get the draged data,also the dragDropEnd method called many times, Is there any way I can get the data and make it called one time.
Please sign in to leave a comment.
Please post the full sources.
My purpose is to drag a note from a tree,When I drop it successful,It should trigger a override method dragDropEnd.
Here is the code:
Create a new class JTreeDragDrop and implements the interface
public class JTreeDragDrop implements DragGestureListener {
public JTreeDragDrop(JTree tree) {
DragSource source = DragSource.getDefaultDragSource();
source.createDefaultDragGestureRecongnizer(tree, DnDConstants.ACTION_COPY_OR_MOVE,this);
source.addDragSourceListener(new DragSourceListener() {
@Override
public void dragDropEnd (DragSourceEvent e) {
// Object o = e.getDragSourceContext().getTransferable();
if (e.getDropSuccess()) {
...
}
}
})
}
}
import this class,use the constructor and transfer the parameter like
JTreeDragDrop dragDrop = new JTreeDragDrop(tree) // JTree tree