JavaFX Switch Scene in Full Screen

I want to switch scenes of my JavaFX application in full screen using the "Next" button. But if I click on this button, it will switch from full-screen mode to window mode and back to full-screen mode within a second. How can I achieve to avoid this and stay in full screen?

Some relevant snippets:

Application.java:

public class Application extends Application {

    @Override
    public void start(Stage stage) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("FXMLMain.fxml"));

        Scene scene = new Scene(root);

        stage.setScene(scene);
        stage.show();
        stage.setFullScreen(true);
        stage.setTitle("AppName");

    }

    public static void main(String[] args) {
        launch(args);
    }

}

FXMLMainController.java:

@FXML
private void handleBtnNext(ActionEvent event) throws Exception{
    Stage stage; 
    Parent root;
    if(event.getSource()==btnNext){
        //get reference to the button stage         
        stage=(Stage) btnNext.getScene().getWindow();
        //load up OTHER FXML document
        root = FXMLLoader.load(getClass().getResource("FXMLOptions.fxml"));
    }
    else{
        stage=(Stage) btnNext.getScene().getWindow();
        root = FXMLLoader.load(getClass().getResource("FXMLMain.fxml"));

    }
    //create a new scene with root and set the stage
    Scene scene = new Scene(root);
    stage.setScene(scene);
    stage.show();
    stage.setFullScreen(true);
}
+4
source share
2 answers

, , ( Java 8u60, OS X 10.11.3). bug.

, , .

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class FullScreenScenes extends Application {
    @Override
    public void start(Stage stage) throws Exception {
        Button next1 = new Button("Show Scene 2");
        StackPane layout1 = new StackPane(next1);
        layout1.setStyle("-fx-background-color: palegreen;");

        Button next2 = new Button("Show Scene 1");
        StackPane layout2 = new StackPane(next2);
        layout2.setStyle("-fx-background-color: paleturquoise;");

        Scene scene = new Scene(layout1);

        next1.setOnAction(event -> scene.setRoot(layout2));
        next2.setOnAction(event -> scene.setRoot(layout1));

        stage.setScene(scene);
        stage.setFullScreen(true);
        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}
+1

( ). . ( Fxid).

-3