[英]How do I create a Resize animation for JavaFX stage?
我一直在嘗試為JavaFX階段進行縮放轉換,以替換應用程序主窗口的當前場景(在本例中為登錄框架)。
當發生這種情況時,由於新場景更大,窗口會以非優雅的方式突然重新調整大小。
有沒有辦法設置一個縮放或重新調整大小的過渡來進行舞台大小調整?
相關代碼:
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) {}
}
}
我真的很喜歡你的想法所以我設法做了一些事情。 我希望這能幫到您。
我使用Timer
每25ms更改一次舞台寬度和高度,以給人一種動畫效果。
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);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.