Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Best way to MouseDrag multiple objects around a scene.

KonradZuseMar 18 2013 — edited Mar 22 2013
So I am having a little trouble trying to drag 3 Box's in a scene.

Originally I had it set up where each was relocated to an x,y translated Z and set to a HWD. Then I figured I would, instead of the mouse click on the box itself, be in the root. From there I would look through all of the root.getChildren() then made that see if it contained the x,y position.


Then from knowing which of my root Children I clicked I did root.getChildren.get(current).setOnDragged to figure out which one was dragged.

The code itself worked except for finding which box I was on.

The issue I find is that I onyl have getX, getSceneX, and getScreenX. X, and SceneX produce the same value, and ScreenX is useless. I tried then to do event.getX() - root.getLayoutX() to make the contains function to work, but it wasn't working and would require me to change up more things. getLayoutX() was = 0 since I didn't set the root location, only the locations of the box's.

From there I kept wondering if there was a better way. Then I thought maybe to loop through every element in my root or in an arrayList(Which is what I used, but realized the root.getchildren should work like the original) but the problem is it keeps only registering the last one in the list, so it just loops and that's it.

So what I want to know is, what would be the best way to figure out what object I'm in?

Originally I use the contains(Swing) but Swing is different, and now especially since we can register mouseEvents to each node, shouldn't we know exactly which one we are on, just by looping through each of them? I figure that's easier than having to check every single mouse position contained within, especially if I have 10000 things to check?

Edited by: KonradZuse on Mar 18, 2013 8:05 PM
This post has been answered by James_D on Mar 20 2013
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 18 2013
Added on Mar 18 2013
14 comments
688 views