1

I am building a booking system application using JFX and the JavaFX scene builder. I thought that to make it look better I could remove the borders, or as the code is, set it as "undecorated". Now I would like to make it able to be dragged on the screen by clicking on the scene and dragging it. I tried many ways but none of them actually worked. I could use some help now.

Thank you in advance.

  • Try to read Pavel's answer on http://stackoverflow.com/questions/16261465/mousedragged-in-javafx-determine-the-card-node-over-which-another-node-is-dragg and think, if you can implement it, when node - a root layout of the scene, and on DnD gesture you use setX,Y of scene – Alexander Kirov May 12 '13 at 12:48
  • 1
    What is your question? Maybe, it is [How to make an undecorated window movable / dragable in JavaFX?](http://stackoverflow.com/a/13460743/852274). – pmoule May 12 '13 at 13:17
  • 1
    possible duplicate of [How to make an undecorated window movable / dragable in JavaFX?](http://stackoverflow.com/questions/13206193/how-to-make-an-undecorated-window-movable-dragable-in-javafx) – jewelsea May 12 '13 at 15:20

1 Answers1

1

I'm using the scene builder, this is what i found.
Using the background pane to move the undecorated window around.

@FXML
private Pane pane;

@Override
public void initialize(URL url, ResourceBundle rb) {
    pane.setOnMousePressed(new EventHandler<MouseEvent>() {

        @Override
        public void handle(MouseEvent t) {
            //System.out.println("Pressed");
            //System.out.println("Mouse : " + t.getX() + " | " + t.getY());
            mouse.setX(t.getX());
            mouse.setY(t.getY());
        }
    });
    pane.setOnMouseDragged(new EventHandler<MouseEvent>() {

        @Override
        public void handle(MouseEvent t) {
            //System.out.println("Dragged");
            //System.out.println("Mouse : " + t.getX() + " | " + t.getY());
            pane.getScene().getWindow().setX( t.getScreenX() - mouse.getX() - 14);
            pane.getScene().getWindow().setY( t.getScreenY() - mouse.getY() - 14);
        }
    });
}   

Mouse class :

public class Mouse {
    private double x = 0;
    private double y = 0;

    public double getX() {
        return x;
    }

    public void setX(double x) {
        this.x = x;
    }

    public double getY() {
        return y;
    }

    public void setY(double y) {
        this.y = y;
    }
}
Ploppy
  • 14,810
  • 6
  • 41
  • 58