changing scenes in full screen

南笙酒味 提交于 2019-12-11 23:03:54

问题


I have read several questions/solutions here that are related to my problems. but nothing seems to work.

so I have a primarystage in fullscreen mode, say if i click a button it changes the scene. but the stage seems to display the taskbar. also I resolved the issue by adding this to all of the scene methods..

stage.setFullScreen(false);
        stage.setFullScreen(true);

BUT, the transition in scenes is not that fluid. first it goes to desktop and back to fullscreen.. which is not the ideal solution.

here is my code for the primary stage:

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

    }

here is my code for changing the scene:

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


    } 

I don't know if this is a bug or something. But i thought if you set your primary stage to full screen. and should be fullscreen all through out regardless of scene.

also, if i have a primary stage in full screen mode.. and a secondary stage NOT in full screen mode. the primary stage seems to disappear if i click a button to show the secondary stage. I wanted to show the secondary page on top of the primary stage, and the primary stage should not be clickable unless the secondary page is closed.

my code for showing the secondary stage:

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


    }

回答1:


Instead of creating a new scene, just change the root of the existing scene:

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
} 

The second thing you are asking is not really possible. In JavaFX, on many platforms "full screen mode" is really implemented as "exclusive screen mode"; so there is a unique window visible. So you would need another solution entirely to this, that didn't involve displaying a new window at all.



来源:https://stackoverflow.com/questions/49223773/changing-scenes-in-full-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!