【发布时间】:2019-06-26 15:13:05
【问题描述】:
我有 BorderPane 作为我的根。左侧包含滑出菜单,中心有容器来保存组件。 当滑出式菜单隐藏并相反时,我想将主容器的长度拉伸到舞台的宽度。
我尝试通过 ScaleTransition 缩放 BorderPane mainContent,但它出错了。 ScaleTransition 只是拉伸,不设置宽度...
@Override
public void start(Stage primaryStage) throws Exception{
Label label = new Label("->");
label.setStyle("-fx-text-fill: orange; -fx-background-color: black");
VBox content = new VBox();
content.setStyle("-fx-background-color: purple");
BorderPane.setAlignment(label, Pos.CENTER);
BorderPane menu = new BorderPane(content,null,label,null,null);
menu.setMaxWidth(250);
menu.setPrefWidth(250);
menu.setTranslateX(-230);
menu.setStyle("-fx-background-color: yellow");
TranslateTransition menuTranslation = new TranslateTransition(Duration.millis(500), menu);
menuTranslation.setFromX(-230);
menuTranslation.setToX(0);
BorderPane mainContent = new BorderPane(new Button("OKEY"),new Button("OKEY"),new Button("OKEY"),new Button("OKEY"),new Button("OKEY"));
mainContent.setStyle("-fx-background-color: cyan");
ScaleTransition mainContenTransition = new ScaleTransition(Duration.millis(500), mainContent);
//TranslateTransition mainContenTranslation = new TranslateTransition(Duration.millis(500), mainContent);
ParallelTransition parallelTransition = new ParallelTransition();
parallelTransition.getChildren().addAll(menuTranslation, mainContenTransition);
menu.setOnMouseEntered(evt -> {
mainContenTransition.setFromX(mainContent.getWidth());
mainContenTransition.setToX(primaryStage.getWidth());
parallelTransition.setRate(1);
parallelTransition.play();
});
menu.setOnMouseExited(evt -> {
mainContenTransition.setFromX(mainContent.getWidth());
mainContenTransition.setToX(primaryStage.getWidth());
parallelTransition.setRate(-1);
parallelTransition.play();
});
mainContent.setStyle("-fx-background-color: cyan");
BorderPane root = new BorderPane(mainContent, null,null,null, menu);
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, 800, 600));
primaryStage.show();
//mainContent.setScaleX(primaryStage.getWidth());
}
【问题讨论】:
标签: java animation javafx javafx-8