package test; import javafx.application.Application; import javafx.event.EventHandler; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.input.MouseEvent; import javafx.scene.paint.Color; import javafx.scene.shape.Circle; import javafx.scene.shape.Rectangle; import javafx.scene.text.Text; import javafx.scene.transform.Rotate; import javafx.stage.Stage; public class RotatedClip extends Application { boolean clip = false; @Override public void start(Stage stage) { stage.setTitle("Rotated Clip"); final Group root = new Group(); final Scene scene = new Scene(root, 600, 450); final Rectangle r = new Rectangle(200, 200, Color.RED); final Circle c = new Circle(150); c.setFill(Color.BLUE); c.setRotationAxis(Rotate.X_AXIS); c.setRotate(75); Text t = new Text(20, 250, "Click anywhere to toggle the blue circle " + "becoming the red's rectangle's clip"); root.getChildren().addAll(r, c, t); scene.setOnMousePressed(new EventHandler() { @Override public void handle(MouseEvent event) { if (clip) { r.setClip(null); root.getChildren().add(c); } else { root.getChildren().remove(c); r.setClip(c); } clip = !clip; } }); stage.setScene(scene); stage.show(); } public static void main(String[] args) { Application.launch(args); } }