Where should I place resource-files like images ?

B

Brandon McCombs

What about the case thing? When loading from jar file case matters.
When loading in windows outside of jar file case does not matter.

Opalinski
(e-mail address removed)
http://www.geocities.com/opalpaweb/


I changed the case of my filenames in my code and it worked. When i
created the files MS Paint made them have uppercase file extensions and
that's also how eclipse was looking at them so I had to refresh the
images/ folder in eclipse after I renamed the files to .gif from .GIF.

thanks Opalinski. I've been working on this for a couple weeks now off
and on and no one could ever figure it out to help.
 
A

Arne Styve

What about the case thing? When loading from jar file case matters.
When loading in windows outside of jar file case does not matter.

Opalinski
(e-mail address removed)
http://www.geocities.com/opalpaweb/

THANK YOU!! You made my day!!

You were absolutely correct. Case DOES matter. The extra anoying part here
(since working in a M$ environment) is that we use Microsoft SourceSafe to
manage our sourcefiles, and of some reason SourceSafe keeps changing the
case on directories and file extensions now and then.....

I renamed from .GIF to .gif, and it worked.....

Thanks!

-Arne
 
S

steve

Arne,

People don't seem to be listening to you about how you have already
tested your code in Eclipse and yet the same code does not work in the
jar file despite your files being in the jar file and in the right
location. A couple days ago in the comp.lang.java.gui newsgroup I
posted a message about this very same problem and so far they have not
been able to help me. I've tried all sorts of combinations of
class.getResource() and classLoader().getResource() and still can't get
icons to load when I use a jar file.

If I run my jar file right above the directory where my icons exist in
my file system then the icons load but that is only because the jar file
is referencing the version if the icons outside of the jar instead of
inside. One person mentioned that the icons need to be in the classpath
but never said how or where to set the classpath. I've tried to set a
classpath in my command window (Windows XP) and then run my jar but it
did not help. If you get the answer please post it so I can try it in
my environment.

yep that's what i find , when my programs don't work.
it's every body else's fault for not listening.

but then I wake up from my dream.



The following code works ( i know because i use it every day)

YOU DO NOT NEED ANY CLASS PATH TO POINT TO YOUR IMAGES IN YOUR ENVIRONMENT,
nor do they need to be on the "class path"

public class MyProvidesReports implements ProvidesReports {


some other code here........
Getpictures(JobParams);
some other code............




private void Getpictures(HashMap ReportParams) {
java.net.URL Source;
java.net.URL Source1;

Source = MyProvidesReports.class.getResource("/Images/Image1.png"); //
this is a fixed format for all java platforms do not use "file.separator
// Source1 = MyProvidesReports.class.getResource("/Images/Chop.png"); //
this is a fixed format for all java platforms do not use "file.separator

// ReportParams.put("MyChop", Source1);
ReportParams.put("CompanyLogo", Source);
}

}
you just need to compile the pictures into a directory

"/Images/Image1.png"


BUT NOTE:
THE CHARACTER CASE, not all platforms ignore the case , "Images" is NOT the
same as "images"

ALSO NOTE
Do not use "file.separator" or strings with paths in, because file separators
are different on each platform.

use the URL class, and a standard separator and it will always work.




the above code is for getting pictures so that their references can be passed
to reports or buttons or whatever.

those 3-5 lines , will save your life every time, on every platform i have
yet tested it on ( windows95/98/se/2000/NT/linux/osx/solaris/yellowdog)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top