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!

Domenico Santoro
  • 147
  • 3
  • 11
  • See [*Animation Basics*](http://docs.oracle.com/javase/8/javafx/visual-effects-tutorial/basics.htm). – trashgod Jul 14 '17 at 11:28
  • You can go [here](https://stackoverflow.com/questions/44734430/memory-leak-in-javafx-indefinite-timeline/44838669#44838669) to see an implementation of lines being rotated about one end like the hands of a clock. – SedJ601 Jul 14 '17 at 15:38

2 Answers2

4

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

Community
  • 1
  • 1
Francesco
  • 396
  • 3
  • 7
  • 17
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.

Domenico Santoro
  • 147
  • 3
  • 11
  • Doesn't that just keep adding more and more transformations to the shape, so it would eventually get sluggish or run out of memory? – digitig Jul 03 '19 at 00:37