Skip to content

Commit

Permalink
add popup functionality: draggable
Browse files Browse the repository at this point in the history
  • Loading branch information
einaskoi committed Apr 13, 2026
1 parent 83093de commit 6d0cf2a
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public abstract class Popup {
protected int height;
protected int x;
protected int y;
protected double dx;
protected double dy;

protected BorderPane root;
protected ScrollPane scrollPane;
protected HBox header;
Expand Down Expand Up @@ -46,6 +49,8 @@ public Popup(int width, int height, int x, int y) {
scrollPane.setContent(content);
root.setTop(header);
root.setCenter(scrollPane);

makeDraggable();
}

public int getWidth() {
Expand Down Expand Up @@ -75,4 +80,16 @@ public VBox getContent() {
public Button getCloseButton() {
return closeButton;
}

private void makeDraggable() {
header.setOnMousePressed(e -> {
dx = e.getSceneX() - root.getLayoutX();
dy = e.getSceneY() - root.getLayoutY();
});

header.setOnMouseDragged(e -> {
root.setLayoutX(e.getSceneX() - dx);
root.setLayoutY(e.getSceneY() - dy);
});
}
}

0 comments on commit 6d0cf2a

Please sign in to comment.