• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 912
  • Last Modified:

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
0
Sreejith22
Asked:
Sreejith22
  • 3
1 Solution
 
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
 
TrigunaCommented:
canImport is called recurrsively until you leave the hold item.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now