2
@FXML
private void opensettings(ActionEvent event) throws IOException {
    Stage stage = null;
    Parent root = null;

    if(event.getSource() == settings && stage.isFullScreen() == true){
        stage = (Stage)settings.getScene().getWindow();
        root = FXMLLoader.load(getClass().getResource("fxml/Settings.fxml"));
        stage.setScene(new Scene(root));
        stage.setTitle("Settings");
        stage.setFullScreen(true);
    }
}

I don't know how to check if my current stage is running in full screen mode or not. Above is my current java code.

Bilesh Ganguly
  • 3,792
  • 3
  • 36
  • 58
David B
  • 21
  • 2
  • Isn't `stage.isFullScreen()` working ? – Hristo Staykov May 19 '16 at 09:25
  • nope its saying : Caused by: java.lang.NullPointerException at sample.OpenController.opensettings(OpenController.java:75) ... 58 more – David B May 19 '16 at 09:46
  • Are you calling `stage.isFullScreen()` before initializing the stage? – Bilesh Ganguly May 19 '16 at 10:21
  • @bilesh i initialized it now but it stills jumps from my fullscene "main window" to a not fullscene "settings window" and actually i want that if my "main window" is in fullscene mode the "settings window" schould be in fullscene mode too... :/ – David B May 19 '16 at 10:38
  • uhm ... `Window` is no `Stage`. At all - but a `Stage` is a `Window`, not the other way around. You're doing a lot of illegal casting up there, that may be your core problem. Casting is *(very)* bad - in pretty much any language other than C / C++ and everyone who tells you otherwise simply is ... inexperienced, a hobbyist at best. Sorry. At least do some **checked** casting, that'll prevent `NullPointerException` or `ClassCastException`. – specializt May 19 '16 at 11:09

1 Answers1

-3

As you can see in the documentation, a Stage is a Window but a Window doesnt know anything about its subclass Stage. You should read this question if you want to learn about upcasting and downcasting. In your case, Window has been constructed as Stage but was stored as Window so all of the Stage-specific fields are now void.

Conclusion : do not downcast if you're inexperienced. At all.

specializt
  • 1,913
  • 15
  • 26