全屏切换场景
changing scenes in full screen
我在这里阅读了几篇 questions/solutions 与我的问题相关的文章。但似乎没有任何效果。
所以我有一个全屏模式的初级阶段,比如说如果我点击一个按钮它会改变场景。但舞台似乎显示任务栏。我还通过将其添加到所有场景方法中解决了这个问题。
stage.setFullScreen(false);
stage.setFullScreen(true);
但是,场景的过渡不是那么流畅。首先它进入桌面然后返回全屏..这不是理想的解决方案。
这是我的初级阶段代码:
public static Stage stage;
private static AnchorPane mainLayout;
@Override
public void start(Stage primaryStage) throws IOException
{
Main.stage = primaryStage;
Main.stage.setTitle("Raven App");
stage.initStyle(StageStyle.UNDECORATED);
stage.setFullScreen(true);
stage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH);
Main.showMain();
}
这是我更改场景的代码:
public static void UserLogin() throws IOException
{
FXMLLoader loader=new FXMLLoader();
loader.setLocation(Main.class.getResource("page/UserHomeLogin.fxml"));
mainLayout=loader.load();
Scene scene=new Scene(mainLayout);
stage.setScene(scene);
stage.show();
}
我不知道这是一个错误还是什么。但我想如果你把你的主要舞台设置为全屏。无论场景如何,都应该全屏显示。
此外,如果我有一个处于全屏模式的初级阶段..和一个不处于全屏模式的次级阶段。如果我点击一个按钮来显示次级阶段,初级阶段似乎消失了。我想在一级页面上显示二级页面,除非二级页面关闭,否则初级阶段应该无法点击。
我的二级展示代码:
public static void PasswordVerify() throws IOException
{
Stage stage = new Stage();
Parent root = FXMLLoader.load(Main.class.getResource("page/PassConfirm.fxml"));
stage.setScene(new Scene(root));
stage.setTitle("popup window");
stage.initModality(Modality.APPLICATION_MODAL);
stage.showAndWait();
stage.show();
}
无需创建新场景,只需更改现有场景的根即可:
public static void UserLogin() throws IOException {
FXMLLoader loader=new FXMLLoader();
loader.setLocation(Main.class.getResource("page/UserHomeLogin.fxml"));
mainLayout=loader.load();
stage.getScene().setRoot(mainLayout);
// or just
// scene.setRoot(mainLayout);
// if you already have a reference to the scene
}
你问的第二件事是不可能的。在 JavaFX 中,在许多平台上 "full screen mode" 实际上实现为 "exclusive screen mode";所以有一个独特的 window 可见。因此,您将完全需要另一种解决方案,根本不涉及显示新的 window。
我在这里阅读了几篇 questions/solutions 与我的问题相关的文章。但似乎没有任何效果。
所以我有一个全屏模式的初级阶段,比如说如果我点击一个按钮它会改变场景。但舞台似乎显示任务栏。我还通过将其添加到所有场景方法中解决了这个问题。
stage.setFullScreen(false);
stage.setFullScreen(true);
但是,场景的过渡不是那么流畅。首先它进入桌面然后返回全屏..这不是理想的解决方案。
这是我的初级阶段代码:
public static Stage stage;
private static AnchorPane mainLayout;
@Override
public void start(Stage primaryStage) throws IOException
{
Main.stage = primaryStage;
Main.stage.setTitle("Raven App");
stage.initStyle(StageStyle.UNDECORATED);
stage.setFullScreen(true);
stage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH);
Main.showMain();
}
这是我更改场景的代码:
public static void UserLogin() throws IOException
{
FXMLLoader loader=new FXMLLoader();
loader.setLocation(Main.class.getResource("page/UserHomeLogin.fxml"));
mainLayout=loader.load();
Scene scene=new Scene(mainLayout);
stage.setScene(scene);
stage.show();
}
我不知道这是一个错误还是什么。但我想如果你把你的主要舞台设置为全屏。无论场景如何,都应该全屏显示。
此外,如果我有一个处于全屏模式的初级阶段..和一个不处于全屏模式的次级阶段。如果我点击一个按钮来显示次级阶段,初级阶段似乎消失了。我想在一级页面上显示二级页面,除非二级页面关闭,否则初级阶段应该无法点击。
我的二级展示代码:
public static void PasswordVerify() throws IOException
{
Stage stage = new Stage();
Parent root = FXMLLoader.load(Main.class.getResource("page/PassConfirm.fxml"));
stage.setScene(new Scene(root));
stage.setTitle("popup window");
stage.initModality(Modality.APPLICATION_MODAL);
stage.showAndWait();
stage.show();
}
无需创建新场景,只需更改现有场景的根即可:
public static void UserLogin() throws IOException {
FXMLLoader loader=new FXMLLoader();
loader.setLocation(Main.class.getResource("page/UserHomeLogin.fxml"));
mainLayout=loader.load();
stage.getScene().setRoot(mainLayout);
// or just
// scene.setRoot(mainLayout);
// if you already have a reference to the scene
}
你问的第二件事是不可能的。在 JavaFX 中,在许多平台上 "full screen mode" 实际上实现为 "exclusive screen mode";所以有一个独特的 window 可见。因此,您将完全需要另一种解决方案,根本不涉及显示新的 window。