A perfect java blog

Posts Tagged drag

Hello guys. Today I’ve got some free time to blog. I have made small chemical solution for making these things happen. I was thinking that most of the game developers really need this type of system even more in the content management system also this kind of stuffs are very useful So I’ve planned to blogged about this (Drag n Drop Cell).

Let’s first look over how the things works for the Draggable of list cell.

Drag and Drop Cell in ListView

The above figure is just the concept which I’ve predicted. You can use your own too But in this post I’m doing all stuffs by this algorithm.By the help of that algorithm I’ve made the things sucess.

Share this:

Hello today I would like to write a blog of how can we make the image draggable in a Stage.
Firstly you need to know more about MouseEvent, ImageView in JavaFx API.

Here we’ll be working around the dragX , dragY properties of MouseEvent class and x, y properties of ImageView. I’ve seen so many blogs but none of the blog had given me the smooth dragging feature in javafx. So here I’m going to start my codes for smooth dragging ability to ImageView .

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

import javafx.stage.Stage;

import javafx.scene.Scene;

import javafx.scene.text.Text;

import javafx.scene.text.Font;

import javafx.scene.image.ImageView;

import javafx.scene.image.Image;

import javafx.scene.input.MouseEvent;

/**

* @author NARAYAN

*/

varmyX:Number=0;

varmyY:Number=0;

vartempX:Number=0;

vartempY:Number=0;

def img:ImageView=bindImageView{

x:bind tempX+myX

y:bind tempY+myY

image:Image{

backgroundLoading:true

url:"{__DIR__}everest.jpg"

}

onMouseReleased:function(e:MouseEvent):Void{

tempX=img.x;

tempY=img.y;

myX=0;

myY=0;

}

onMouseDragged:function(e:MouseEvent):Void{

myX=e.dragX;

myY=e.dragY;

}

}

Stage{

title:"ImageView Smoothly Dragging"

scene:Scene{

width:450

height:400

content:[

img

]

}

}

After using this code you can see the mouse dragging is being binded with the ImageView ‘x’ and ‘y’ position. Futher more for saving the temporary x and y position of ImageView I’ve used mouseReleased() event.