This week's book giveaways are in the C/C++ and Spring forums. We're giving away four copies each of C++ Concurrency and Spring Integration in Action and have the authors on-line! See this thread and this one for details.
I am trying to drag and drop tree nodes within the same JTree. I have a code which uses Java 1.2 java.awt.dnd. I would like to use TransferHandler and newer implementation. I have found a code which works when JTree is drop target but there is no code where Jtree is drag source and drop target. Can somone point good link?
JTrees are complex and there are so many choices/decisons to make and ways of doing things that it's difficult to say much about implementing drag and drop in them. Here's an example, as requested, using the j2se 1.6 improvements. Most of the code in the TransferHandler comes from various parts of the tutorial.
<blockquote>code:<pre name="code" class="core">
</pre></blockquote>
This message was edited 1 time. Last update was at by Campbell Ritchie
Gregory Gawl
Greenhorn
Joined: Aug 12, 2008
Posts: 1
posted
0
Wow, thanks Craig! Your code was a giant help to me to see the plentyful yapping (sorry for the sarcasm, it was of course very helpful too!) of the tutorials put together and made work by someone!
I myself was struggling to see my tree implement DnD successfully until I saw your code above.
I'd like to ask yo, if I might use part of your code in my customTreeDataHandler class? (As your code works, and mine not ... looks like my understanding of dnd still didn't reach a level where I can actually make it do what I'd like it to do )
Thanks for your answer in advance!
- Gregory
Craig Wood
Ranch Hand
Joined: Jan 14, 2004
Posts: 1535
posted
0
use part of your code in my customTreeDataHandler class Yes, of course.
Melki Joe
Greenhorn
Joined: Aug 29, 2008
Posts: 24
posted
0
Hi Craig Wood,
I too have a problem in JTree that is I want to move the JTree nodes to another JTree without changing its structure. but only the selected nodes should move. Help me in this issue.
Thank you.
Evgeny Krylov
Greenhorn
Joined: Jan 25, 2009
Posts: 4
posted
0
Melki Joe wrote:Hi Craig Wood,
I too have a problem in JTree that is I want to move the JTree nodes to another JTree without changing its structure. but only the selected nodes should move. Help me in this issue.
That's quite some kick, Evgeny, and I'm sorry to say that its intended purpose is not achieved either: Melki hasn't posted since December 16th.
Andre Uhres
Greenhorn
Joined: Nov 23, 2008
Posts: 23
posted
0
Evgeny Krylov wrote:
Melki Joe wrote:Hi Craig Wood,
I too have a problem in JTree that is I want to move the JTree nodes to another JTree without changing its structure. but only the selected nodes should move. Help me in this issue.
Your code might be of public interest, if only it were compilable. Here ist only one example of many broken statements in your code:
Evgeny Krylov
Greenhorn
Joined: Jan 25, 2009
Posts: 4
posted
0
Andre Uhres wrote:
Evgeny Krylov wrote:
Melki Joe wrote:Hi Craig Wood,
I too have a problem in JTree that is I want to move the JTree nodes to another JTree without changing its structure. but only the selected nodes should move. Help me in this issue.
Thanks for the heads up! I hadn't looked at that page in a long time.
Alain Couniot
Greenhorn
Joined: Jan 31, 2011
Posts: 2
posted
0
Very nice illustration and almost perfect! Thanks, Craig! It works but there is nevertheless a subtle bug (in the method below)
As it is, as you multiply the moves, it repeatedly wraps nodes into a new node (instead of only its userObject).
A correct implementation would be, e.g.,
Based on this working example, I have cleaned up a messy class of mine (with more generic purposes) that had become unmaintainable.
A big thank again !
Alain
Alain Couniot
Greenhorn
Joined: Jan 31, 2011
Posts: 2
posted
0
Well, actually, I have used
(Don't remember exactly why)
Alain
Alessio Pollero
Greenhorn
Joined: Jan 17, 2012
Posts: 1
posted
0
The problem with the TreeTransferHandler is that if i drag an element of the JTree into another position in the same level, the element will be removed from the JList and will be lost.
If the element is dropped into the same level of the JTree, the element should not be removed from the JTree but leaved in the location it was without doing anything ...
subject: JTree - drag and drop inside one tree - Java 1.6