Animation 滑动隐藏节点

Animation 滑动隐藏节点,animation,javafx,Animation,Javafx,我有个问题 我的问题 如何使矩形在滑动时隐藏在按钮下方。我不想让它从按钮的另一边出来 package javafxapplication24; import javafx.animation.TranslateTransition; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.fxml.FXMLLoa

我有个问题

我的问题

如何使矩形在滑动时隐藏在按钮下方。我不想让它从按钮的另一边出来

package javafxapplication24;

import javafx.animation.TranslateTransition;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Pos;
import javafx.scene.Group;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.GridPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.util.Duration;

/**
 *
 * @author phili_000
 */
public class JavaFXApplication24 extends Application {
    public    Button by;
      
    @Override
    public void start(Stage stage) throws Exception {
    
  FlowPane root = new FlowPane( );
  root.setAlignment(Pos.CENTER);
  Button butt = new Button("Play");
  Rectangle rect = new Rectangle(200,40);
 
     rect.setFill(Color.VIOLET);
     
  TranslateTransition transition = new TranslateTransition(Duration.millis(6000),rect);
        Scene scene = new Scene(root,700,700);
      
        transition.setToX(-300);
 
        root.getChildren().addAll(butt,rect);
       butt.setOnAction((event) -> {
   transition.play();
});
        stage.setScene(scene);
        stage.show();
    }
              
 
    public static void main(String[] args) {
        launch(args);
    }
    
}

我尽力解释,但如果你有任何问题。或者评论我如何改进我的问题。请不要犹豫,点击“添加评论”按钮,告诉我您的想法。

先添加矩形,然后添加按钮:

root.getChildren().addAll(text, butt);

可能重复@Fabian我不知道如何使用toBack或tofront在这里你不应该这样做;然而,
FlowPane
是一个不适合这种动画的布局,也许你应该先改变它……谢谢你的回答,它确实解决了我遇到的另一个问题。但是我需要矩形不要从按钮的另一边出来。你的回答让矩形滑到按钮下面,太棒了!。我希望它只有在滑出时才可见。