【问题标题】:Sliding Hidden Node滑动隐藏节点
【发布时间】:2016-03-26 16:49:50
【问题描述】:

我有一个问题。

我的问题

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

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);
    }
    
}

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

【问题讨论】:

  • Z-Order in JavafFX的可能重复
  • @Fabian 我不知道如何使用 toBack 或 toFront
  • 这里你不应该这样做;但是FlowPane 是一种不适合此类动画的布局,也许您应该先更改它...

标签: animation javafx


【解决方案1】:

先添加矩形,再添加按钮:

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

【讨论】:

  • 感谢您的回答,它确实解决了我遇到的另一个问题。但我需要矩形不要从按钮的另一侧出来。您的回答使按钮下方的矩形滑动很棒!我希望它只有在滑出时才可见。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-01-17
  • 1970-01-01
  • 2022-07-27
  • 2013-02-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多