简体   繁体   English

JavaFX-ImageView-为什么不渲染该图像?

[英]JavaFX - ImageView - Why isn't this image rendering?

ImageView starterImage = new ImageView(new Image("file:Fallen.png"));
root.getChildren().add(starterImage);

That's just a snip from a larger file. 那只是大文件的片段。 Why isn't it appearing? 为什么不出现? The program runs in NetBeans without any errors at all, and all the other nodes are showing up except for the image. 该程序在NetBeans中运行,完全没有任何错误,除图像外,其他所有节点都显示出来。

All help appreciated. 所有帮助表示赞赏。

I assume you have an Image in the project that you want it to work even if you export your project as a jar file. 我假设即使您将项目导出为jar文件,您在项目中也要使用它的图像。

Let's say that your image is in the resource folder(resources) and under the package images(recommended way). 假设您的图片位于资源文件夹(资源)中,并且位于图片包下方(推荐方式)。

Image image = new Image(getClass.getResourceAsStream("/images/flower.png");

If your image is in the same package as your java file: 如果您的映像与Java文件位于同一软件包中:

Image image = new Image(getClass.getResourceAsStream("/flower.png");

Here are all the ways you can load an Image (URL,FILE,CLASSPATH) 您可以通过以下所有方式加载Image (URL,FILE,CLASSPATH)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM