如何添加动画以最小化JavaFX?

如何添加动画以最小化JavaFX?,java,javafx,Java,Javafx,我使用的是AnimateFX库,它只是节点动画的汇编 AnimationFX fx = new ZoomOut(background); fx.setOnFinished(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent actionEvent) { //background.setScaleX(1.0D); //background.s

我使用的是AnimateFX库,它只是节点动画的汇编

AnimationFX fx = new ZoomOut(background);
fx.setOnFinished(new EventHandler<ActionEvent>() {
    @Override
    public void handle(ActionEvent actionEvent) {
        //background.setScaleX(1.0D);
        //background.setScaleY(1.0D);
        //background.setScaleZ(1.0D);
        //background.setOpacity(1.0D);

        // -- some wait function --

        Stage stage = (Stage) background.getScene().getWindow();
        stage.setIconified(true);
    }
});
fx.play();
编辑#2

这是我的主课

package app;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
        primaryStage.initStyle(StageStyle.TRANSPARENT);
        Scene scene = new Scene(root);
        scene.setFill(Color.TRANSPARENT);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}
这是我的sample.fxml文件

<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>

<VBox fx:id="background" prefHeight="500.0" prefWidth="400.0" style="-fx-background-color: transparent" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="app.Controller">
  <AnchorPane fx:id="content" prefHeight="464.0" prefWidth="500.0" style="-fx-background-color: #3D4956&#10;" VBox.vgrow="ALWAYS">
    <children>
      <ImageView fx:id="minimize" fitHeight="150.0" fitWidth="200.0" layoutX="100.0" layoutY="175.0" onMouseClicked="#onMinimizeClicked" pickOnBounds="true" preserveRatio="true" />
    </children>
  </AnchorPane>
</VBox>

我不知道这种行为的原因,但我设法通过在
FXML的
ImageView
中添加一个图像来解决它

<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>

<VBox fx:id="background" prefHeight="500.0" prefWidth="400.0" style="-fx-background-color: transparent" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="sample.Controller">
<AnchorPane fx:id="content" prefHeight="464.0" prefWidth="500.0" style="-fx-background-color: #3D4956&#10;" VBox.vgrow="ALWAYS">
    <children>
        <ImageView fx:id="minimize" fitHeight="150.0" fitWidth="200.0" layoutX="100.0" layoutY="175.0" onMouseClicked="#onMinimizeClicked" pickOnBounds="true" preserveRatio="true" >
            <Image url="file:image/iamge.png"/>
        </ImageView>
    </children>
</AnchorPane>
</VBox>


您能否提供可运行的代码,以便我们可以重新生成您有经验的行为?我在问题编辑中提供了它。您能否提供fxml文件?我已经厌倦了您的代码,它正在按预期运行。我没有体验到您提到的那种行为,或者我无法使用您提供的代码重新生成它。我提供了我的其余文件
<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>

<VBox fx:id="background" prefHeight="500.0" prefWidth="400.0" style="-fx-background-color: transparent" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="sample.Controller">
<AnchorPane fx:id="content" prefHeight="464.0" prefWidth="500.0" style="-fx-background-color: #3D4956&#10;" VBox.vgrow="ALWAYS">
    <children>
        <ImageView fx:id="minimize" fitHeight="150.0" fitWidth="200.0" layoutX="100.0" layoutY="175.0" onMouseClicked="#onMinimizeClicked" pickOnBounds="true" preserveRatio="true" >
            <Image url="file:image/iamge.png"/>
        </ImageView>
    </children>
</AnchorPane>
</VBox>