0 Replies Latest reply: Nov 27, 2012 6:48 AM by svanimpe RSS

    Anchors vs translate properties

      I wrote the following example to test scrolling with a trackpad (touch events).
      It works fine: the ImageView is clipped by the rectangle and scrolls underneath.

      When I uncomment the two lines to position the viewGroup in the root AnchorPane, everything is all over the place when I scroll.
      Can someone explain why this happens, or is this a bug ?
      If I remove the anchors and simply set the translateX and translateY properties of viewGroup to 10 (to get the same positioning), everything works just fine again. I'm just wondering why the anchors don't work.
      public void start(Stage primaryStage) {
          AnchorPane root = new AnchorPane();
          Group viewGroup = new Group();
      //        AnchorPane.setTopAnchor(viewGroup, 10.0);
      //        AnchorPane.setLeftAnchor(viewGroup, 10.0);
          viewGroup.getTransforms().add(new Scale(1.5, 1.5));
          Rectangle clip = RectangleBuilder.create()
          final ImageView view = new ImageView(App.class.getResource("/resources/background.png").toExternalForm());
          view.setOnScroll(new EventHandler<ScrollEvent>() {
              public void handle(ScrollEvent t) {
                  double newX = view.getTranslateX() + t.getDeltaX();
                  if (newX < -480) {
                      newX += 480;
                  if (newX > 0) {
                      newX -= 480;
          Scene scene = new Scene(root, 720, 360);