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){
stage=(Stage) btnNext.getScene().getWindow();
root = FXMLLoader.load(getClass().getResource("FXMLOptions.fxml"));
}
else{
stage=(Stage) btnNext.getScene().getWindow();
root = FXMLLoader.load(getClass().getResource("FXMLMain.fxml"));
}
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
stage.setFullScreen(true);
}
source
share