3
votes

I'm trying to rotate an ImageView 90 degrees (JavaFX) each time the button is clicked:

private void rotate90(ActionEvent e){
    if(currentImage != null){
        imageView.setRotate(90);    
    }
}

but my code only rotates ImageView once, and after that it just stops.

2
Your code example is a bit short: How do you call the method? Why do you check currentImage a where is it changed? - hotzst
Method is called by button: - V.Savage
MenuItem rot90 = new MenuItem(bundle.getMessage("rot90")); rot90.setOnAction(this::rotate90); - V.Savage
currentImage is the image displayed in scrollpane - V.Savage
basically, I'm working on mimic of photoshop, where user should be able to open an image and apply some filters to it, as well as rotating the image - V.Savage

2 Answers

8
votes

Initially the value of you rotate property is 0. Once you execute rotate90, you set the property to 90. Each subsequent call does the same. See the JavaDoc You can achieve your desired behaviour through a Rotation or by updating the value:

imageView.setRotate(imageView.getRotate() + 90); 
0
votes

Use this code: CW_90 -> ClockWise90 degree.

BufferedImage sourceImage;
BufferedImage outputImage;
Scalr.rotate(sourceImage, Scalr.Rotation.CW_90, outputImage);