I would like some recommendations on how to implement the transition on the slide for the panel when the user clicks the button, just like Material Design does this for sliding menus.
This is a video link that illustrates my need.
I tried ScaleTransition, TranslateTransition, but they did not do the trick.
The way I'm trying to implement it is inefficient.
// swipeMenuPane is builded in SceneBuilder and it is hidden, // opacity = 0.0 and setX() = -getPrefWidth(); @FXML AnchorPane swipeMenuPane; @FXML Button menuButton; menuButton.setOnMouseClicked(e-> { swipeMenuPane.setOpacity(1.0); swipeTransition.play() }); TranslateTransition swipeTransition = new TranslateTransition(); swipeTransition.setNode(swipeMenuPane); swipeTransition.setDuration(Duration.millis(500)); swipeTransition.setToX(swipeMenuPane.getPrefWidth());
--- UPDATE ---
Here is an example of a Gluon application downloaded from here . This is a gradle project, and I modified it to display a button instead of the default label.
I want to compress AnchorPane when the user clicks a button.
What am I missing?
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-> { System.out.println("swiping..."); anim.play(); }); AnchorPane pane = new AnchorPane(); pane.setStyle("-fx-background-color: coral"); pane.getChildren().add(btn);
--- UPDATE 2 ---
I managed to implement something similar to what I want using my own JavaFX API and external libraries.
Although, I ran into some problems.
- Abbreviation AnchorPane does not abbreviate / move ANY of its children, as they remain in their layout positions.
- Abbreviation for any panel other than AnchorPane. REDUCING / moving their child nodes except ImageView nodes.
The following two images illustrate the first issue I came across.
This is AnchorPane (with coral color across the entire width, expanded) inside AnchorPane (root panel with gray color).

And this happens when you press the "Menu" button to compress / hide it. As you can see, the panel with a coral shade is compressed / hidden, but not its nodes (Label, ImageView)

I am posting all the code to reproduce the problem myself:
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 -> { if (isExpanded) hideSwapPane().play(); else showSwapPane().play(); }); Button btnClose = new Button("Close"); btnClose.setLayoutX(590); btnClose.setLayoutY(5); btnClose.setOnMouseClicked(e -> 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-> { 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-> { isExpanded = true; btnMenu.setMouseTransparent(false); }); return expandPanel; } }
--- UPDATE 3 ---
I changed the Felipe Guizar Diaz code to provide me according to my needs, since I want a shadow effect on my transparent scene window.
When I press the menu button to display the left panel, it appears in front of the shadow. Although in SceneBuilder I placed a StackPane with dropshadow effect in front of all nodes.
This is an βartifactβ when I click to show the menu and start playing the open transition ...
How can i fix this?
