如何将图像添加到 netbeans Java 项目中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3904386/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 03:55:21  来源:igfitidea点击:

how to add an image into netbeans Java project

javanetbeans

提问by Khoi

I'm doing a simple Java project on Netbeans. And I'm stuck not knowing how to add my own image into the code. It kept throwing IOException no matter where I put the image. This sounds ridiculous but it really got me stuck.

我正在 Netbeans 上做一个简单的 Java 项目。而且我不知道如何将我自己的图像添加到代码中。无论我将图像放在哪里,它都会不断抛出 IOException 。这听起来很荒谬,但它确实让我陷入了困境。

采纳答案by kskjon

If you run the program from netbeans, the root folder should be the same as the root of the project folder. That is, the folder which contains build.xml and manifest.mf.

如果从 netbeans 运行程序,则根文件夹应与项目文件夹的根相同。即包含 build.xml 和 manifest.mf 的文件夹。

If putting your image directly in that folder, and loading it without any path given doesn't work, then you will have too look at your code and see if you can find any errors.

如果将您的图像直接放在该文件夹中,并且在没有给出任何路径的情况下加载它不起作用,那么您也需要查看您的代码,看看是否可以找到任何错误。

回答by Abhay Desai

Try looking at you project directory and find where the html/xhtml files are. Mostly it will be located inside the web directory within the project directory projectname/build/web. That will be source for the image tag in your html page you can directly give the name of the image for "src".

尝试查看您的项目目录并找到 html/xhtml 文件所在的位置。大多数情况下,它将位于项目目录projectname/build/web 中的 web 目录内 。这将是您的 html 页面中图像标签的来源,您可以直接为“src”指定图像的名称。