I am trying to set a transparent png as a stage's background. The problem is that the transparent part of the png is not not transparent in javafx. This is the code I am using:
Pane root = new Pane();
root.setStyle("-fx-background-color: transparent");
ImageView img = new ImageView();
img.setStyle("-fx-background-color: transparent");
img.setImage(new Image(getClass().getClassLoader().getResource("transparent_png.png").toExternalForm()));
root.getChildren().add(img);
Scene scene = new Scene(root, 500, 500);
scene.setFill(Color.TRANSPARENT);
stage.initStyle(StageStyle.TRANSPARENT);
stage.setScene(scene);
stage.show();
Am I doing something wrong or is it not possible? Regards,
It is certainly possible. It is likely your image is not actually transparent. Here is a complete example which creates an image in code with transparent pixels, saves it to a file, then reads the file into an image object and displays it. The only other difference from your code are to make it easy to exit the application by clicking on it.