我有一個基本的JavaFX應用程序,打開因爲如此JavaFX的全屏模式不工作
public class MyApplication extends Application {
private Stage stage;
public static void main(String[] args) {
Console.setDebug();
launch(args);
}
@Override
public void start(Stage primaryStage) {
// set stage as primary
stage = primaryStage;
stage.setFullscreen(true);
stage.show();
stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
public void handle(WindowEvent we) {
System.out.println("Closing application...");
}
});
}
}
現在切換畫面我有這個功能,我稱之爲
private void replaceScene(String resource, IControlledScreen controller) {
try {
controller.setApp(this);
FXMLLoader loader = new FXMLLoader(getClass().getResource(resource));
loader.setController(controller);
Pane screen = (Pane) loader.load();
Scene scene = new Scene(screen);
stage.setScene(scene);
stage.setFullscreen(true);
} catch (Exception e) {
System.out.println("Cannot load resource " + resource);
System.out.println(e.getMessage());
}
}
調用示例將
public void goToHome() {
replaceScene("/fxml/HomeView.fxml", new HomeController());
}
現在,當我運行應用程序,第一個屏幕是全屏模式,然後當我改變屏幕,屏幕重新大小到窗口大小,然後再次更改爲全屏?我曾嘗試加入
stage.setFullscreen(false);
我打電話
stage.setFullscreen(true);
但這兩種工作之前。如何在不調整大小的情況下更改屏幕/場景?
也可以使用代碼切換全屏模式,比方說,如果我希望用戶能夠選擇全屏模式,可以這樣做嗎?
沒有工作,在stage.getScene()下降,我猜是因爲它是空的,但使用你的代碼和額外的檢查,現在的作品謝謝你! – Gillardo 2014-11-06 11:36:08