title: JavaFX: how to create slide in animation effect for a pane (inside a transparent stage)
body: <p>I would like some guidelines on how to implement a slide in transition for a pane when user presses a button, just like Material Design does it for sliding menus.</p>
  
  <p>This is a video <a href="https://www.youtube.com/watch?v=kQIscHJgBKY" rel="noreferrer">link</a> that illustrates my need.</p>
  
  <p>I tried ScaleTransition, TranslateTransition, but they didn't do the trick.</p>
  
  <p>The way I'm trying to implement it is not efficient.</p>
  
  <pre><code>// swipeMenuPane is builded in SceneBuilder and it is hidden,
  // opacity = 0.0 and setX() = -getPrefWidth();
  @FXML AnchorPane swipeMenuPane;
  @FXML Button menuButton;
  
  menuButton.setOnMouseClicked(e-&gt; {
      swipeMenuPane.setOpacity(1.0);
      swipeTransition.play()
  });
  
  TranslateTransition swipeTransition = new TranslateTransition();
  swipeTransition.setNode(swipeMenuPane);
  swipeTransition.setDuration(Duration.millis(500));
  swipeTransition.setToX(swipeMenuPane.getPrefWidth());
  </code></pre>
  
  <hr>
  
  <p><strong>--- UPDATE ---</strong></p>
  
  <p>Here is the sample Gluon Application downloaded from <a href="http://docs.gluonhq.com/charm/0.0.1/#_download_sample_application" rel="noreferrer">here</a>. It's a gradle project and I modified it to display a button instead of the default label.</p>
  
  <p>I want to shrink the AnchorPane when user clicks the button.</p>
  
  <p>What am I missing?</p>
  
  <pre><code>package com.helloworld;
  
  import com.gluonhq.charm.glisten.animation.ShrinkExpandAnimation;
  import javafx.application.Application;
  import javafx.scene.Scene;
  import javafx.scene.control.Button;
  import javafx.scene.layout.AnchorPane;
  import javafx.scene.layout.StackPane;
  import javafx.stage.Stage;
  
  public class HelloWorld extends Application {
  
      ShrinkExpandAnimation anim;
  
      @Override
      public void start(Stage stage) {        
          Button btn = new Button("Click Me!");
          btn.setOnMouseClicked(e-&gt; {
              System.out.println("swiping...");
              anim.play();
          });
  
          AnchorPane pane = new AnchorPane();
          pane.setStyle("-fx-background-color: coral");
          pane.getChildren().add(btn);
  
          // false to shrink or true to expand
          anim = new ShrinkExpandAnimation(pane, false);
  
          Scene scene = new Scene(new StackPane(pane), 640, 480);
  
          stage.setScene(scene);
          stage.show();
      }
  }
  </code></pre>
  
  <hr>
  
  <p>--- UPDATE 2 ---</p>
  
  <p>I managed to implement something similar to what I want using native JavaFX API and no external libraries.</p>
  
  <p>Although, I ran into some issues.</p>
  
  <ol>
  <li>Shrinking an AnchorPane does NOT shrink/move ANY of its children nodes, because they stay in their layout positions.</li>
  <li>Shrinking any other Pane except AnchorPane DOES shrink/move its children nodes except from ImageView nodes.</li>
  </ol>
  
  <p>The next two images illustrate the 1st issue I ran into.</p>
  
  <p>This is an AnchorPane (with coral color at its full width; expanded) inside an AnchorPane (root pane with grey color).</p>
  
  <p><a href="https://i.stack.imgur.com/5FPPw.png" rel="noreferrer"><img src="https://i.stack.imgur.com/5FPPw.png" alt="expanded"></a></p>
  
  <p>And this is what happens when you click Menu button to shrink/hide it. As you can see the coral-colored pane got shrinked/hidden, but NOT its nodes (Label, ImageView)</p>
  
  <p><a href="https://i.stack.imgur.com/WL8Lt.png" rel="noreferrer"><img src="https://i.stack.imgur.com/WL8Lt.png" alt="collapsed"></a></p>
  
  <p>I post the whole code to reproduce the issue yourself:</p>
  
  <pre><code>public class SwipeMenuDemo extends Application {
  
      AnchorPane swapPane;
      Button btnMenu;
      boolean isExpanded = true;
  
      @Override
      public void start(Stage stage) {    
          Label swapPaneLabel = new Label("Expandable Pane");
          swapPaneLabel.setMinWidth(0);
  
          ImageView swapPaneImage = new ImageView("http://vignette1.wikia.nocookie.net/jfx/images/5/5a/JavaFXIsland600x300.png");
          swapPaneImage.setLayoutY(100);
  
          Label rootPaneLabel = new Label("Root Pane");
          rootPaneLabel.setStyle("-fx-font-size: 60;");
          rootPaneLabel.setLayoutX(180);
          rootPaneLabel.setLayoutY(180);
  
          swapPane = new AnchorPane();
          swapPane.setPrefSize(640, 440);
          swapPane.setMinWidth(0);
          swapPane.setLayoutY(40);
          swapPane.setStyle("-fx-background-color: coral; -fx-font-size: 52;");
          swapPane.getChildren().addAll(swapPaneImage, swapPaneLabel);
  
          btnMenu = new Button("Menu");
          btnMenu.setLayoutX(5);
          btnMenu.setLayoutY(5);
          btnMenu.setOnMouseClicked(e -&gt; {
              if (isExpanded) hideSwapPane().play();
              else showSwapPane().play();
          });
  
          Button btnClose = new Button("Close");
          btnClose.setLayoutX(590);
          btnClose.setLayoutY(5);
          btnClose.setOnMouseClicked(e -&gt; Platform.exit());
  
          AnchorPane rootPane = new AnchorPane();
          rootPane.setStyle("-fx-background-color: grey;");
          rootPane.getChildren().addAll(btnMenu, btnClose, rootPaneLabel, swapPane);
  
          Scene scene = new Scene(rootPane, 640, 480);
  
          stage.setScene(scene);
          stage.initStyle(StageStyle.UNDECORATED);
          stage.show();
      }
  
      private Animation hideSwapPane() {            
          btnMenu.setMouseTransparent(true);
  
          Animation collapsePanel = new Transition() {
              {
                  setCycleDuration(Duration.millis(2500));
              }
  
              @Override
              protected void interpolate(double fraction) {
                  swapPane.setPrefWidth(640 * (1.0 - fraction));
              }
          };
  
          collapsePanel.setOnFinished(e-&gt; {
              isExpanded = false;
              btnMenu.setMouseTransparent(false);
          });
  
          return collapsePanel;
      }
  
      private Animation showSwapPane() {            
          btnMenu.setMouseTransparent(true);
  
          final Animation expandPanel = new Transition() {
              {
                  setCycleDuration(Duration.millis(2500));
              }
  
              @Override
              protected void interpolate(double fraction) {
                  swapPane.setPrefWidth(640 * fraction);
              }
          };
  
          expandPanel.setOnFinished(e-&gt; {
              isExpanded = true;
              btnMenu.setMouseTransparent(false);
          });
  
          return expandPanel;
      }
  }
  </code></pre>
  
  <hr>
  
  <p><strong>--- UPDATE 3 ---</strong></p>
  
  <p>I modified the code Felipe Guizar Diaz provide me, according to my needs, since I want a dropshadow effect on my transparent stage window.</p>
  
  <p>When I click the menu button to show the left pane it shows up in front of the shadow. Even though in SceneBuilder I've placed the StackPane with the dropshadow effect in front of all nodes.</p>
  
  <p>This is the "artifact" when I press to show the menu and starts playing the open transition...</p>
  
  <p>How can I fix it?</p>
  
  <p><a href="https://i.stack.imgur.com/X4bWw.png" rel="noreferrer"><img src="https://i.stack.imgur.com/X4bWw.png" alt="shadow artifact"></a></p>