简体   繁体   English

源文件夹图像eclipse / java

[英]Source folder images eclipse/java

How to crate a source folder with images and then use them in that same project? 如何创建包含图像的源文件夹,然后在同一项目中使用它们? I have an "image" folder in src and I indicated that it is a source folder via build-path. 我在src中有一个“图像”文件夹,我通过构建路径表示它是源文件夹。 I tried like a million ways to put those images on my JFrame-JLabels but none of them seems to work(it does with absolute path).What is the best way to do that?Relative path needed... 我尝试了大约一百万种方法将这些图像放置在我的JFrame-JLabels上,但它们似乎都不起作用(这与绝对路径有关)。做到这一点的最佳方法是什么?需要相对路径...

Make a resource folder. 制作一个资源文件夹。 Call it "res" or whatever you want. 称它为“ res”或任何您想要的。 Or you can make a method which sets directory already to folder you want and you just input file name 或者,您可以创建一种方法,将目录设置为所需的文件夹,而只需输入文件名

img = imageName.png img = imageName.png

buffImg = ImageIO.read(new File("C:\Project\src\images\" + img));

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

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