title: JavaFX Clipping an ImageView to an Ellipse within an AnchorPane
body: <p>I have been building an app where I want to display one big image inside an ellipse to mimic the roof of a planetarium.
  Clipping the ImageView displaying image to the ellipse with <code>myImageView.setClip(myEllipse)</code> has worked gracefully until the last version of my app where the AnchorPane I am adding the Ellipse into seems not to appreciate my clipping an image within it.</p>
  
  <p>The error I get for the line <code>myImageView.setClip(myEllipse)</code> is the following:</p>
  
  <p>Caused by: </p>
  
  <blockquote>
    <p>java.lang.IllegalArgumentException: Node's clip set to incorrect value
    (node already connected, node  = ImageView@a13b0a6, clip =
    ObjectProperty [bean: ImageView@a13b0a6, name: clip, value: null]).</p>
  </blockquote>
  
  <p>What I understand is that I am creating some kind of loop within the scene graph, but i can't figure out where.</p>
  
  <p>This is my code (the whole interface is "hardcoded")</p>
  
  <pre><code>package opinarium3;
  
  import java.io.BufferedReader;
  import java.io.FileReader;
  import java.io.IOException;
  import javafx.application.Application;
  import javafx.beans.property.DoubleProperty;
  import javafx.beans.property.SimpleDoubleProperty;
  import javafx.event.EventHandler;
  import javafx.geometry.Insets;
  import javafx.geometry.Pos;
  import javafx.scene.Scene;
  import javafx.scene.control.Button;
  import javafx.scene.control.Label;
  import javafx.scene.control.TextArea;
  import javafx.scene.image.Image;
  import javafx.scene.image.ImageView;
  import javafx.scene.input.MouseEvent;
  import javafx.scene.layout.AnchorPane;
  import javafx.scene.layout.HBox;
  import javafx.scene.layout.Pane;
  import javafx.scene.layout.VBox;
  import static javafx.scene.layout.VBox.setMargin;
  import javafx.scene.shape.Ellipse;
  import javafx.scene.text.Font;
  import javafx.stage.Stage;
  
  /**
   *
   * @author Admin
   */
  public class Opinarium3 extends Application {
      private Ellipse ceiling;
      private ImageView ceiling_image;
      private VBox nav;
      private HBox buttonSet;
      private Label presentation_title;
      private TextArea info;
      private Button previous;
      private Button comment;
      private Button next;
      private double sx;
      private double sy;
      private DoubleProperty coordX = new SimpleDoubleProperty(0);
      private DoubleProperty coordY = new SimpleDoubleProperty(0);
  
      @Override
      public void start(Stage primaryStage) throws IOException {
          AnchorPane root = new AnchorPane();
          Scene primaryScene = new Scene(root, 900, 800);
          primaryScene.getStylesheets().add(Opinarium3.class.getResource("Opinarium3.css").toExternalForm());
          initializeCeiling(root);
          initializeNav(root);
          initializeContent();
          initializePrimaryStage(primaryStage, primaryScene);
          primaryStage.show();
      }
  
      private void initializePrimaryStage(Stage primaryStage, Scene primaryScene) {
          primaryStage.setTitle("Planetario de San José - Cartelera de Presentaciones");
          primaryStage.setScene(primaryScene);
          primaryStage.setWidth(900);
          primaryStage.setHeight(800);
          primaryStage.minHeightProperty().setValue(800);
          primaryStage.minWidthProperty().setValue(900);
      }
  
      /**
       * @param args the command line arguments
       */
      public static void main(String[] args) {
          launch(args);
      }
  
      private void initializeCeiling(AnchorPane root) {
          ceiling = new Ellipse();
          ceiling.centerXProperty().bind(root.widthProperty().multiply(0.5));
          ceiling.centerYProperty().setValue(0);
          ceiling.radiusXProperty().bind(root.widthProperty().multiply(0.8));
          ceiling.radiusYProperty().bind(root.heightProperty().multiply(0.6));
          root.getChildren().add(ceiling);
      }
  
      private void initializeNav(AnchorPane root) {
          nav = new VBox();
          initializeControls(nav);
          AnchorPane.setBottomAnchor(nav, 20.0);
          AnchorPane.setLeftAnchor(nav, 120.0);
          AnchorPane.setRightAnchor(nav, 120.0);
          root.getChildren().add(nav);
      }
  
      private void initializeControls(VBox nav) {
          info = new TextArea();
          setMargin(info, new Insets(10, 0, 0, 0));
          info.setWrapText(true);
          info.setEditable(false);
          buttonSet = new HBox();
          initializeButtonSet(nav);
          presentation_title = new Label("Título de la Presentación");
          presentation_title.setId("titulo");
          nav.alignmentProperty().setValue(Pos.CENTER);
          nav.getChildren().addAll(presentation_title, info, buttonSet);
      }
  
      private void initializeButtonSet(VBox nav) {
          previous = new Button("&lt;");
          comment = new Button("Doy mi opinión");
          comment.setId("comment_button");
          next = new Button("&gt;");
          buttonSet.spacingProperty().bind(nav.widthProperty().multiply(0.15));
          buttonSet.setAlignment(Pos.CENTER);
          setMargin(buttonSet, new Insets(10, 0, 0, 0));
          buttonSet.getChildren().addAll(previous, comment, next);
      }
  
      private void initializeContent() throws IOException {
          try {
              BufferedReader br = new BufferedReader(new FileReader("src/opinarium3/media/joyas/joyas.txt"));
              String title = br.readLine();
              String length = br.readLine();
              String description = br.readLine();
              this.presentation_title.setText(title);
              this.info.setText("\n"+description+"\n\nDuración: "+length);
              br.close();
  
  
              ceiling_image = new ImageView(new Image(Opinarium3.class.getResourceAsStream("media/joyas/joyas.jpg")));
              ceiling_image.setClip(ceiling);
              /*
              ceiling_image.setOnMousePressed(new EventHandler&lt;MouseEvent&gt;() {
                  @Override
                  public void handle(MouseEvent t) {
                      sx = t.getSceneX() - coordX.doubleValue();
                      sy = t.getSceneY() - coordY.doubleValue();
                  }
              });
              ceiling_image.setOnMouseDragged(new EventHandler&lt;MouseEvent&gt;(){
                  @Override
                  public void handle(MouseEvent t){
                      if(t.getSceneX() - sx &lt; 0){
                          coordX.setValue(t.getSceneX() - sx);
                      }
                      if(t.getSceneY() - sy &lt; 0){
                          coordY.setValue(t.getSceneY() - sy);
                      }
                  }
              });
              ceiling_image.xProperty().bind(coordX);
              ceiling_image.yProperty().bind(coordY);
                      */
          }catch(IOException e){}
      }
  }
  </code></pre>