JavaFX Resizing Undecorated Window

Hello, I’m using an undecorated JavaFX window (stage) and want to be able to resize it. I grabbed the following code and got it working (sort of):

resizeButton.setOnMousePressed(new EventHandler<MouseEvent>() {
	public void handle(MouseEvent e) {
		dx = JavaGameMaker.editorWindow.getWidth() - e.getX();
		dy = JavaGameMaker.editorWindow.getHeight() - e.getY();
	}
});
resizeButton.setOnMouseDragged(new EventHandler<MouseEvent>() {
	public void handle(MouseEvent event) {
		JavaGameMaker.editorWindow.setWidth(event.getX() + dx);
		JavaGameMaker.editorWindow.setHeight(event.getY() + dy);
	}
		});

I’m using a borderless button at the bottom right corner, that the user can grab to resize the window.
What happen’s is this:

(http://imgur.com/4Az2WFF - sorry for the bad quality, imgur made some problems)

The corner doesn’t stay at the cursor.
Has anybody got an idea, on how to fix this?

It seems like the error has a 2:1 relationship of some sort (width and height are changed half as much as the mouse is moved).

Is there some sort of scaling going on for the display of either the resizeButton or the editorWindow?

dx and dy are constant during the mouse drag, yes?

Yes, they are. They are defined as static objects in the same class and only get accessed by the posted code.

Alright, I got the solution myself:

public void handle(MouseEvent e) {
    Stage window = JavaGameMaker.editorWindow; // static access to my window's stage
    window.setWidth(e.getScreenX() - window.getX());
    window.setHeight(e.getScreenY() - window.getY());
}