aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Drag and Drop between 2 JLists - ReportingListTransferHandler Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Drag and Drop between 2 JLists - ReportingListTransferHandler" Watch "Drag and Drop between 2 JLists - ReportingListTransferHandler" New topic
Author

Drag and Drop between 2 JLists - ReportingListTransferHandler

Matt Kurz
Ranch Hand

Joined: Jan 02, 2010
Posts: 40
Hello,

I tried this example. It's exactly what I want. The author has described it here

I've attached a screenshot with "right 3" in the left AND right list. I think this may not be. It is reproducable if you drag and drop sometimes between both lists, you can see that suddenly one entry is in both lists.

Does somebody have a correct example or does somebody see the bug?

Regards
mattk1



[Thumbnail for jlistbug.jpeg]

Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2200
    
    7
Try the ListTransferHandler from the Drop Demo example found in the Swing tutorial.
Matt Kurz
Ranch Hand

Joined: Jan 02, 2010
Posts: 40
Rob Camick wrote:Try the ListTransferHandler from the Drop Demo example found in the Swing tutorial.

Thanks for your help! I've taken a look at the ListTransferHandler and decided to try my luck with ReportingListTransferHandler again. I've read the Swing tutorial until "Export Methods" and supposed the error is in the exportDone method. I can reproduce the error with this little modification:


The ReportingListTransferHandler is unchanged. Start this now and try to drag "right 6" to the left list. The result is "right 6" in both lists and "right 7" deleted. I want that right 7 is not deleted. It should be where right 6 was.

I suggested that the condition if (addCount > 0) is not correct, because the author wrote:
// If we are moving items around in the same list, we
// need to adjust the indices accordingly since those
// after the insertion point have moved.


So my question is, if you agree with my suggestion: How can I identify if we are moving items around in the same list? Here is the relevant method with some comments:

I've already tried a debugger session with eclipse, and read about getDropLocation(), but until now I do not see the solution.
Matt Kurz
Ranch Hand

Joined: Jan 02, 2010
Posts: 40
I wrote a completly new TransferHandler. Seems all fine now.
Elias Matheus Camacho
Greenhorn

Joined: Oct 26, 2011
Posts: 1
I find a way to make the code posted work. You were correct when you said the problem was in the exportDone function.

The way I fix it, was in the importData function, I specified that the addIndex variable should only be set when the source and the target is the same. In code, this translates to:

Then in the exportDone function, y replaced the condition you posted that was mistaken with:

This way, this only gets executed when the drag and drop it's in the same jlist.

Hope this helps!
 
Consider Paul's rocket mass heater.
 
subject: Drag and Drop between 2 JLists - ReportingListTransferHandler