changing scenes in full screen

2019-08-16 07:32发布

问题:

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.