Javafx 如何添加转换动画以切换JAVA FXML

Javafx 如何添加转换动画以切换JAVA FXML,javafx,fxml,Javafx,Fxml,1) 在fxml文件之间切换时如何在javafx中添加过渡动画。 2) 如何在按钮中添加css效果,如悬停效果和流行按钮效果 我正在从事javafx项目。我在使用动画添加更改fxml时遇到问题。我还需要关于如何为按钮创建css的帮助 下面是切换fxml的代码 public void start(Stage primaryStage) { try { stage = primaryStage; gotohome(); primaryS

1) 在fxml文件之间切换时如何在javafx中添加过渡动画。 2) 如何在按钮中添加css效果,如悬停效果和流行按钮效果

我正在从事javafx项目。我在使用动画添加更改fxml时遇到问题。我还需要关于如何为按钮创建css的帮助

下面是切换fxml的代码

 public void start(Stage primaryStage) {

    try {
        stage = primaryStage;

        gotohome();

        primaryStage.show();
    } catch (Exception ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }
}

public void gotohome() {
    try {
        FXMLController home = (FXMLController) replaceSceneContent("Homepage.fxml");
        home.setApp(this);
    } catch (Exception ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }
}

public void gotoproductwise() {
    try {
        SampleController product_wise = (SampleController) replaceSceneContent("/product_wise/product_wise.fxml");
        product_wise.setApp(this);
    } catch (Exception ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }
}


private Initializable replaceSceneContent(String fxml) throws Exception {
    FXMLLoader loader = new FXMLLoader();
    InputStream in = Main.class.getResourceAsStream(fxml);
    loader.setBuilderFactory(new JavaFXBuilderFactory());
    loader.setLocation(Main.class.getResource(fxml));
    AnchorPane page;
    try {
        page = (AnchorPane) loader.load(in);
    } finally {
        in.close();
    }

    // Store the stage width and height in case the user has resized the window
    double stageWidth = stage.getWidth();
    if (!Double.isNaN(stageWidth)) {
        stageWidth -= (stage.getWidth() - stage.getScene().getWidth());
    }

    double stageHeight = stage.getHeight();
    if (!Double.isNaN(stageHeight)) {
        stageHeight -= (stage.getHeight() - stage.getScene().getHeight());
    }

    Scene scene = new Scene(page);
    if (!Double.isNaN(stageWidth)) {
        page.setPrefWidth(stageWidth);
    }
    if (!Double.isNaN(stageHeight)) {
        page.setPrefHeight(stageHeight);
    }

   // stage.setOpacity(1);
    stage.setScene(scene);
    stage.sizeToScene();
    return (Initializable) loader.getController();
}

对于第二个问题,这里是一些示例样式:

.button:hover {
    -fx-background-color: #9ACD32;
}

对于第二个问题,这里是一些示例样式:

.button:hover {
    -fx-background-color: #9ACD32;
}

你可以发布一些你如何在FXML之间切换的代码吗?你可以发布一些你如何在FXML之间切换的代码吗?谢谢你的回复。我给出了切换fxml的代码。谢谢您的回复。我给出了切换fxml的代码。