users
[Top] [All Lists]

RE: [cinjug-users] JTree and DND

To: "'Brian Engel'" <BEngel@xxxxxxxxxxxxx>
Subject: RE: [cinjug-users] JTree and DND
From: "Ford, Eric (LNG-DAY)" <eric.ford@xxxxxxxxxxxxxx>
Date: Thu, 19 Jun 2003 11:13:04 -0400
Cc: "Cinjug - Users (E-mail)" <users@xxxxxxxxxx>
Delivered-to: mailing list users@cinjug.org
Mailing-list: contact users-help@cinjug.org; run by ezmlm
Here is an article that I used when doing what you are.

It was helpful to me, maybe you can use this to solve your problem.

http://www.javaworld.com/javaworld/javatips/jw-javatip97.html

> -----Original Message-----
> From: Brian Engel [mailto:BEngel@xxxxxxxxxxxxx]
> Sent: Thursday, June 19, 2003 10:55 AM
> To: users@xxxxxxxxxx
> Subject: Re: [cinjug-users] JTree and DND
> 
> 
> I can get them as doubles fine dtde.getLocation.getX() but 
> the JTree object method getPathForLocation(int x,int y) 
> requires the ints. 
> 
> Here is what I am doing....
> 
> TreePath 
> myTreePath=myJTree.getPathForLocation((int)dtde.getLocation().
> getX(),(int)dtde.getLocation().getY());
> 
> Am I missing something here?
> 
> 
> >>> "James Carman" <james@xxxxxxxxxxxxxxxxxxxx> 06/19/03 10:47AM >>>
> You don't have to use them as doubles.  Just use...
> 
> dtde.getLocation().x or dtde.getLocation().y
> 
> They're accessible fields.  Not exactly the best 
> encapsulation, but it gets
> the job done.  I have NO idea why they did that double vs. 
> int thing!  It's
> ridiculous!  The ints would get automagically converted to 
> doubles wherever
> needed.
> 
> ----- Original Message ----- 
> From: "Brian Engel" <BEngel@xxxxxxxxxxxxx>
> To: <users@xxxxxxxxxx>
> Sent: Thursday, June 19, 2003 10:38 AM
> Subject: Re: [cinjug-users] JTree and DND
> 
> 
> That's alright,  I figured out what you meant in your first 
> message :-)....
> 
> It kinda of works. The problem is that it isn't precise 
> enough. i.e. If I
> grab (in my example) grandchild1 by the uppermost left corner 
> of the "leaf
> icon" and drag it, the getPathForLocation() method thinks I 
> am holding the
> "Child1" node. I think this is because the 
> getPathForLocation() method takes
> ints and the DropTargetDragEvent returns doubles. So I have 
> to "down" cast
> them to ints.
> 
> There has to be an elegant solution to this, otherwise I 
> don't see how you
> can create a windows "explorer" type application in Java.
> 
> 
> So I guess I'll keep reading the API! :-)
> 
> 
> 
> 
> 
> >>> "James Carman" <james@xxxxxxxxxxxxxxxxxxxx> 06/19/03 10:24AM >>>
> Hey, Brian.  Did that work for you?  Sorry I was so short 
> with my response,
> but I was busy when I wrote it.  Anyway, you can get the x,y 
> locations from
> the drag event.  Then, you can ask the JTree what "path" is 
> terminated at
> that location.  From there, you can get the node at the end 
> of the path.
> That should get you what you're looking for.  Hope that 
> helps.  Good Luck!
> JTree is tricky (at least for me, as I'm usually a 
> server-side developer)!
> 
> ----- Original Message ----- 
> From: "Brian Engel" <BEngel@xxxxxxxxxxxxx>
> To: <users@xxxxxxxxxx>
> Sent: Thursday, June 19, 2003 9:06 AM
> Subject: [cinjug-users] JTree and DND
> 
> 
> 
> I am trying to create a JTree which I can drag and drop one
> DefaultMutableTreeNode on top of another (with hopes of 
> actually moving it
> there).
> 
> I have figured out how to create a class that implements 
> DropTargetListener
> and I can successfully "capture" events that JTree fires. 
> What I want to
> know is there a way to figure out what object 
> (DefaultMutableTreeNode, in
> this case) has been dropped on top of?
> 
> i.e. I have a simple JTree like this....
> 
> Root
> |
> ?--Child1
> |              |----GrandChild1
> |---Child2
> 
> I want to drag GrandChild1 and drop it on top of Root. I need 
> to figure out
> (through the listener I suppose) what object was dropped on 
> top of what.
> Primarily so I can rebuild the tree with GrandChild1 as a 
> Child of Root.
> 
> 
> Do this make any sense :-) ?
> 
> 
> Any help would be appreciated.....
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 

<Prev in Thread] Current Thread [Next in Thread>