作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个程序,它首先启动一个小闪屏,5 秒后它继续到一个新的阶段。
奇怪的是,到目前为止它工作得很好,但是现在我开始构建新的阶段,我在类中声明新的节点来使用它。
现在,启动画面突然变成白色背景,注释掉之前创建的节点将使图像恢复为透明。
public static Pane pane = new Pane(); //this is fine
//Uncommenting this Node will change the splash screen background white
//public static TextArea textArea = new TextArea();
public static Image splashImage = new Image(Class.class.getClassLoader().getResourceAsStream("image.png"));
public static ImageView splashImageView = new ImageView(splashImage);
public static BorderPane splashPane = new BorderPane(splashImageView);
public static Scene splashScene = new Scene(splashPane);
@Override
public void start(Stage primaryStage) throws Exception {
splashScene.setFill(Color.TRANSPARENT);
primaryStage.setScene(splashScene);
primaryStage.initStyle(StageStyle.TRANSPARENT);
primaryStage.show();
}
这是我的代码的缩短版本
这可能是因为内存问题还是其他什么原因?我从来没有遇到过这样的事情。
感谢任何帮助。
最佳答案
仅当创建控件(即 Control
的实例或其子类之一)时,才会加载默认样式表。 (其背后的想法是避免为管理所有自己的图形且不使用任何控件(例如游戏或模拟)的应用程序加载 CSS 的性能开销。)
默认样式表将根节点(示例中的 splashPane
)的背景颜色设置为非常浅的灰色(具体来说,它比颜色 #ececec< 亮 26.4%)/
)。
由于文本区域是类中唯一的控件,因此创建它会导致加载默认样式表,从而将 splashPane
的背景颜色设置为非常浅的灰色。
如果您需要实例化控件并希望 Pane 的背景透明,则需要在外部 CSS 中指定:
splashStyle.css
:
.root {
-fx-background-color: transparent ;
}
还有
@Override
public void start(Stage primaryStage) throws Exception {
splashScene.setFill(Color.TRANSPARENT);
splashScene.getStylesheets().add("splashStyle.css");
primaryStage.setScene(splashScene);
primaryStage.initStyle(StageStyle.TRANSPARENT);
primaryStage.show();
}
(为了快速检查这是否有效,您可以使用
进行测试splashPane.setStyle("-fx-background-color: transparent; ");
)
关于JavaFX:仅声明节点即可更改其他节点的背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50311541/
这实际上是我问的问题的一部分here ,该问题没有得到答复,最终被标记为重复。 问题:我只需使用 @Autowired 注释即可使用 JavaMailSender。我没有通过任何配置类公开它。 @Co
我是一名优秀的程序员,十分优秀!