Skip to content

Instantly share code, notes, and snippets.

@tsathis
Created June 27, 2020 05:27
Show Gist options
  • Save tsathis/cc16e1a224e2a639badf790ddcf05fc4 to your computer and use it in GitHub Desktop.
Save tsathis/cc16e1a224e2a639badf790ddcf05fc4 to your computer and use it in GitHub Desktop.
Drag an undecorated window of JavaFX ##javafx
@FXML
private StackPane parentPane;
double xOffset;
double yOffset;
@FXML
void handleOnMouseDraggedBtnCtrlMainView(MouseEvent event) {
Stage stage = ( Stage ) parentPane.getScene().getWindow();
stage.setX(event.getScreenX() + xOffset);
stage.setY(event.getScreenY() + yOffset);
}
@FXML
void handleOnMousePressedBtnCtrlMainView(MouseEvent event) {
Stage stage = ( Stage ) parentPane.getScene().getWindow();
xOffset = stage.getX() - event.getScreenX();
yOffset = stage.getY() - event.getScreenY();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment