• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Drag and Drop between 2 JLists - ReportingListTransferHandler

 
Matt Kurz
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
jlistbug.jpeg
screenshot
[Thumbnail for jlistbug.jpeg]
 
Rob Camick
Ranch Hand
Posts: 2536
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try the ListTransferHandler from the Drop Demo example found in the Swing tutorial.
 
Matt Kurz
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote a completly new TransferHandler. Seems all fine now.
 
Elias Matheus Camacho
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic