how to make transparent scene and stage in javafx?

For modena.css (the default JavaFX look and feel definition in Java 8), a slight shaded background was introduced for all controls (and also to panes if a control is loaded).

You can remove this by specifying that the default background is transparent. This can be done by adding the following line to your application’s CSS file:

.root { -fx-background-color: transparent; }

This is in addition to other settings you already have in your code to initialize the style of the stage and background fill of the scene.

stage.initStyle(StageStyle.TRANSPARENT);
scene.setFill(Color.TRANSPARENT);

Note: in the questions’s sample code, an additional stage (initStage) is created instead of using the passed in stage for the start method. The passed in stage can be initialized, utilized and shown directly by your code rather than creating an additional initStage.

Leave a Comment