1

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!

2
  • See Animation Basics. Commented 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. Commented Jul 14, 2017 at 15:38

2 Answers 2

5

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));

The documentation

Some tutorial

Adding more is difficult given the lack of your code

Sign up to request clarification or add additional context in comments.

1 Comment

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.
1

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

Doesn't that just keep adding more and more transformations to the shape, so it would eventually get sluggish or run out of memory?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.