i have a stage and set it's style to
after some seconds i need to change initStyle to Decorate but when i use
give me this exception
java.lang.IllegalStateException: Cannot set style once stage has been set visible
What Not to Do
As the exception says, you
Cannot set style once stage has been set visible
So, if you can't do that, don't try to do it.
What to Do
Instead, hide your transparent stage and create a new stage with the new style. When doing so, be careful because the default behaviour is to shut down the JavaFX system once all stages have been hidden. To avoid this either switch off the default behaviour and explicitly shutdown the JavaFX system when needed or ensure that you always have at least one Window visible.
// initialize your splash stage. Platform.setImplicitExit(false); splashStage.initStyle(StageStyle.TRANSPARENT); . . . // create your main stage. Stage mainStage = new Stage(); mainStage.setScene(mainScene); mainStage.initStyle(StageStyle.DECORATED); mainStage.setOnHide(event -> Platform.exit()) . . . // on some later event hide your splash stage and show your main stage. splashStage.hide(); mainStage.show();
Here is a full executable sample based on an answer to a previous question => How to create Splash screen with transparent background in JavaFX.