我有一个基本的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