Got the drag thingto work
This commit is contained in:
parent
e1210440f4
commit
d1a1ce0511
@ -1,15 +1,19 @@
|
||||
package sample;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.StageStyle;
|
||||
|
||||
public class Main extends Application {
|
||||
|
||||
private double xOffset = 0;
|
||||
private double yOffset = 0;
|
||||
|
||||
volatile double[] posOrigin = {0, 0};
|
||||
|
||||
@Override
|
||||
@ -26,8 +30,19 @@ public class Main extends Application {
|
||||
root.lookup("#exit").setOnMouseClicked(event -> primaryStage.close());
|
||||
|
||||
// Drag
|
||||
root.lookup("#rectangle").setOnMouseDragged(event -> {
|
||||
|
||||
root.lookup("#rectangle").setOnMousePressed(new EventHandler<MouseEvent>() {
|
||||
@Override
|
||||
public void handle(MouseEvent event) {
|
||||
xOffset = event.getSceneX();
|
||||
yOffset = event.getSceneY();
|
||||
}
|
||||
});
|
||||
root.lookup("#rectangle").setOnMouseDragged(new EventHandler<MouseEvent>() {
|
||||
@Override
|
||||
public void handle(MouseEvent event) {
|
||||
primaryStage.setX(event.getScreenX() - xOffset);
|
||||
primaryStage.setY(event.getScreenY() - yOffset);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user