Ferid Raouf
Ferid Raouf

Reputation: 23

Showing a PNG file with transparent background using javafx

Am actually working on a splash Screen unsing javaFX, everythink works fine but I want to show a png image with a transparent background on the splash screen, but am unable to do it, can someone please tell me if it's possible to do it from JavaFX Scene Builder or not ?

Upvotes: 0

Views: 4592

Answers (1)

Robert
Robert

Reputation: 470

I'm in a bit of a rush, but below is a quick example to show you how it can be done by setting the StageStyle to Transparent and the scene fill to the color "transparent".

@Override
public void start(Stage aStage) throws Exception {
    Pane root = new Pane();
    ImageView img = new ImageView();
    img.setImage(new Image(getClass().getResource("pathToYourPngLocatedInYourResourcesFolder.png").toExternalForm()));
    root.getChildren().add(img);
    Scene scene = new Scene(root, 500, 500);
    scene.setFill(Color.TRANSPARENT);
    aStage.initStyle(StageStyle.TRANSPARENT);
    aStage.setScene(scene);
    aStage.show();
}

Let me know how it works out :)

Upvotes: 1

Related Questions