0

I'm trying to load images from my project directory.

I have images in a folder, starting at the project directory:

Project/res/textures

How might I easily access these images so I can say:

"/textures/image.png" when loading an image?

tbcrawford
  • 387
  • 1
  • 8
  • 23

1 Answers1

1

You want textures to be in the root of your class path. An easy way to do that is to mark Project/res as a Resources Root.

jackrabbit
  • 5,525
  • 1
  • 27
  • 38
  • I believe I've tried this on my mac. I've made Project/res a Resource root and then try to access it and it won't work. Do I need to make textures a source root folder? – tbcrawford Apr 17 '15 at 13:21
  • An image is not source, is it? Try using `textures/image.png` (without the leading slash). How are you loading the image? The easiest way is using [ImageIcon](http://docs.oracle.com/javase/7/docs/api/javax/swing/ImageIcon.html#ImageIcon(java.lang.String)), but you can also take a look at [this question](http://stackoverflow.com/questions/3294196/load-resource-from-anywhere-in-classpath). – jackrabbit Apr 18 '15 at 05:43