【发布时间】: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是一种不适合此类动画的布局,也许您应该先更改它...