How do I create resizing animation for a JavaFX stage?

I've been trying to do a scaling transformation for the JavaFX phase to replace the current scene of the application's main window (in this case, the login box)

InputStream is = null;
try {
    is = getClass().getResourceAsStream("/fxml/principal.fxml");
    Region pagina = (Region) cargadorFXML.load(is);
    cargadorFXML.<ContenedorPrincipal>getController().setEscenario(escenario);

    final Scene escena = new Scene(pagina,900,650);

    escena.setFill(Color.TRANSPARENT);
    escenario.setScene(escena);
    escenario.sizeToScene();
    escenario.centerOnScreen();
    escenario.show();
} catch (IOException ex) {
    // log "Unable to load the main application driver"
    log.error("No fue posible cargar el controlador principal de la aplicación."); 
    log.catching(ex);
} finally {
    if (is != null) {
        try {
            is.close();
        } catch (IOException e) {}
    }
}

Solution

I really like your idea, so I managed to do something

import java.util.Timer;
import java.util.TimerTask;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class SmoothResize extends Application {

    @Override
    public void start(final Stage stage) throws Exception {
        stage.setTitle("Area Chart Sample");
        Group root = new Group();
        Scene scene  = new Scene(root,250,250);
        stage.setResizable(false);

        Timer animTimer = new Timer();
        animTimer.scheduleAtFixedRate(new TimerTask() {
            int i=0;

            @Override
            public void run() {
                if (i<100) {
                    stage.setWidth(stage.getWidth()+3);
                    stage.setHeight(stage.getHeight()+3);
                } else {
                    this.cancel();
                }
                i++;
            }

        },2000,25);

        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
***
下一篇>>