The default style sheet is only loaded if a control (i.e an instance of Control
or one of its subclasses) is created. (The idea behind this is to avoid the performance overhead of loading CSS for applications that manage all their own graphics and don't use any controls, such as games or simulations.)
The default stylesheet sets the background color of the root node (the splashPane
in your example) to a very light grey (specifically, it is 26.4% brighter than the color #ececec
).
Since the text area is the only control in your class, creating it causes the default style sheet to be loaded, which sets the background color of the splashPane
to a very light grey.
If you need to instantiate controls and want the background of the pane to be transparent, you need to specify that in an external CSS:
splashStyle.css
:
.root {
-fx-background-color: transparent ;
}
And
@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();
}
(As a quick check that this will work, you can just test with
splashPane.setStyle("-fx-background-color: transparent; ");
)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…