一旦阶段设置可见,无法设置样式 [英] Cannot set style once stage has been set visible

查看:1141
本文介绍了一旦阶段设置可见,无法设置样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个舞台并将其风格设置为

i have a stage and set it's style to

stage.initStyle(StageStyle.TRANSPARENT);

几秒后我需要将initStyle更改为装饰但是当我使用

after some seconds i need to change initStyle to Decorate but when i use

stage.initStyle(StageStyle.Decorate );

给我这个例外

java.lang.IllegalStateException: Cannot set style once stage has been set visible

任何想法?

推荐答案

什么不该做

正如例外所述,你


一旦阶段设置为可见,就无法设置样式

Cannot set style once stage has been set visible

所以,如果你不能这样做,不要试图这样做。

So, if you can't do that, don't try to do it.

怎么做

相反,隐藏透明舞台并使用新风格创建一个新舞台。
这样做时要小心,因为默认行为是在隐藏所有阶段后关闭JavaFX系统。要避免这种情况,请关闭默认行为并在需要时显式关闭JavaFX系统,或者确保始终至少有一个窗口可见。

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();  

相关

这是完整的可执行样本,基于对上一个问题的回答=> 如何在JavaFX中创建具有透明背景的启动画面

Here is a full executable sample based on an answer to a previous question => How to create Splash screen with transparent background in JavaFX.

这篇关于一旦阶段设置可见,无法设置样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆