I'm looking for a simple way to rotate shapes in javafx. Right now I've a scene with multiples shapes and I want to use a rotate button to select one of them and set a rotation of a specified angle, but I've no idea how to do that. Can anyone help? Thanks in advance!
-
See Animation Basics.trashgod– trashgod2017-07-14 11:28:16 +00:00Commented Jul 14, 2017 at 11:28
-
You can go here to see an implementation of lines being rotated about one end like the hands of a clock.SedJ601– SedJ6012017-07-14 15:38:56 +00:00Commented Jul 14, 2017 at 15:38
Add a comment
|
2 Answers
Is a simple request with many implementation alternatives, and some solutions are readily available Code:
Text text = new Text("This is a test");
text.setX(10);
text.setY(50);
text.setFont(new Font(20));
text.getTransforms().add(new Rotate(30, 50, 30));
Adding more is difficult given the lack of your code
1 Comment
Domenico Santoro
My problem is how can i get the shape from the many ones shapes that are on the scene and then use the Rotate transformation.
I was only able to get the button rotate with this code:
@FXML
private void rotateButtonHandle(ActionEvent event) {
//handle for rotate
rotateButton.setOnMouseClicked((MouseEvent t) -> {
System.out.println("X " + (t.getX()));
System.out.println("\nY "+(t.getY()));
Node shape = (Node) t.getSource();
shape.getTransforms().add(new Rotate(20.0,t.getX(),t.getY()));
});
}
I dont know how to get the shape in the scene.
1 Comment
digitig
Doesn't that just keep adding more and more transformations to the shape, so it would eventually get sluggish or run out of memory?