Move / Resize a Window using Drag
846788Jun 8 2012 — edited Jun 12 2012Instead of using the OS controls for moving/resizing a window, I want to provide my
own controls.
Is is possible to use the Drag APIs to move / resize the application window.
I have tried
@FXML
private void handleResizePressed(MouseEvent event) {
System.out.println("Resize Pressed");
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
x = event.getScreenX() - stage.getX();
y = event.getScreenY() - stage.getY();
event.consume();
}
@FXML
private void handleResizeDragged(MouseEvent event) {
System.out.println("Resize Dragged");
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
stage.setX(event.getScreenX() - x);
stage.setY(event.getScreenY() - y);
event.consume();
}
And set the Control's onMousePressed and onDragDetected to the 2 handlers respectively.
But the drag doesn't happen continuously, i.e. the mouse press event is called, and then the dragdetected event is called, but only once,
I expect events for the entire duration of the dragging process.
Also simply pressing and releasing the mouse (without dragging) gives a 'java.lang.IllegalArgumentException: argument type mismatch' exception.