【问题标题】:changing scenes in full screen全屏切换场景
【发布时间】:2018-03-11 18:51:46
【问题描述】:

我在这里阅读了几个与我的问题相关的问题/解决方案。但似乎没有任何效果。

所以我有一个全屏模式的初级阶段,比如说如果我点击一个按钮,它会改变场景。但舞台似乎显示任务栏。我也通过将它添加到所有场景方法来解决这个问题..

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();


    }

【问题讨论】:

  • 我很抱歉,因为我不太熟悉更改根节点。我在场景构建器中制作了单独的 fxml,并将它们视为场景.. 用户的 fxml,管理员的 fxml 等等。

标签: javafx fullscreen modality


【解决方案1】:

无需创建新场景,只需更改现有场景的根:

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 中,许多平台上的“全屏模式”真正实现为“独屏模式”;所以有一个独特的窗口可见。因此,您将需要另一个完全不涉及显示新窗口的解决方案。

【讨论】:

  • 回复非常迅速。非常感谢。它现在运行得很好,感谢您的代码。对于第二个问题,感谢您让我知道,也许我会创建一个将出现的窗格并禁用另一个窗格。对不起我的英语。
  • @AndresMagallanes 是的,创建一些其他窗格并将其显示在当前内容的顶部是我的想法;这可能不是最简单或最干净的解决方案,但应该是可能的。
  • @AndresMagallanes 如果此答案解决了您的问题,请接受它作为正确答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-10-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-14
  • 2016-04-13
  • 1970-01-01
相关资源
最近更新 更多