I have a polygon (triangle shape). I want to make it draggable with mouse. Below is the code that I tried, but with this code I am not able to drag it smoothly. Please let me know how can I achieved to make it draggable smoothly.
public void start(Stage primaryStage) throws Exception {
AnchorPane pane = new AnchorPane();
final Polygon polygon = new Polygon();
polygon.getPoints().addAll(new Double[]{
50.0, 50.0,
30.0, 70.0,
70.0, 70.0 });
pane.getChildren().add(polygon);
Scene scene = new Scene(pane, 200, 200, Color.WHITE);
primaryStage.setScene(scene);
primaryStage.show();
polygon.setOnMouseDragged(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
polygon.setLayoutX(event.getX());
polygon.setLayoutY(event.getY());
}
});
}