Drag and Drop issue in Jlist - Transferhandler not working

Hi all,
I have a problem associated with the drag and drop of components into a Jlist.
When I drag component out of a Jlist, the control reaches inside transfer handler, but when I try to insert a component into the Jlist, the control does not reach inside Jlist transfer handler.
This is the piece of my code.

>>     jlist.setDropMode(DropMode.INSERT);
     jlist.setDragEnabled(true);
     jlist.setTransferHandler(new TransferHandler()
            {
          
                  List fileList;
                  boolean export = false;
                  List<File> newList = null;
                  
                  protected Transferable createTransferable(JComponent c)
                  {
                        System.out.println("inside handler");
                                ..............................
                                ..............................


Please help me with this issue.
Any help in this regard will be well appreciated with points.
Regards,
Sreejith
Sreejith22Asked:
Who is Participating?
 
TrigunaCommented:
canImport is called recurrsively until you leave the hold item.
0
 
TrigunaCommented:
You can choose either one of them.
>>     jlist.setDropMode(DropMode.INSERT);
     jlist.setDragEnabled(true);

If you want items to be dragged out of JList then enable the drag.
If you want items to be dopped into JList then use the DropMode.

Hope this helps.
0
 
Sreejith22Author Commented:
>>If you want items to be dragged out of JList then enable the drag.
If you want items to be dopped into JList then use the DropMode.


What if I want both?
0
 
TrigunaCommented:
This is how it works.

When you drag, createTransferable, canImport is called. And when you drop it, ImportData, canImport, exportDone is called.
If you are implementing everything then you have to override all the methods which are required.
As soon as you hold an item, createTransferable of that component Transferable is called and hence you are getting inside that block.

You can implement everything without a problem. But I didnt find a reason for single JList to implement both drag and drop together.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.