1 private double x = 0;
2 private double y = 0;
3
4 private void makeCanDrag() //make sure this method is called at the start.
5 {
6
7 parent.setOnMousePressed(new EventHandler<MouseEvent>() {
8 @Override
9 public void handle(MouseEvent event) {
10 x = event.getSceneX();
11 y = event.getSceneY();
12 }
13 });
14
15 parent.setOnMouseDragged(new EventHandler<MouseEvent>() {
16 @Override
17 public void handle(MouseEvent event) {
18 stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
19 stage.setX(event.getSceneX() - x);
20 stage.setY(event.getSceneY() - y);
21 stage.setOpacity(.8f);
22 }
23 });
24 parent.setOnDragDone(event -> {
25 stage.setOpacity(1.0f);
26 });
27 parent.setOnMouseReleased(event -> {
28 stage.setOpacity(1.0f);
29 });
30 }