Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Move / Resize a Window using Drag

846788Jun 8 2012 — edited Jun 12 2012
Instead 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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 10 2012
Added on Jun 8 2012
9 comments
5,095 views