Showing a PNG file with transparent background using javafx

半腔热情 提交于 2019-12-24 19:44:10

问题


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 ?


回答1:


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 :)



来源:https://stackoverflow.com/questions/56774974/showing-a-png-file-with-transparent-background-using-javafx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!