On May 5, 10:45 pm, Lew <l...@[EMAIL PROTECTED]
> wrote:
> Redbeard wrote:
> > I've got an app that uses images that will be used with a
> > JToggleButton. I started out with
> > Icon myIcon = new ImageIcon("images\\myImage.jpg");
>
> Use forward slashes, and newImageIcon( getClass().getResource(
> "images/myImage.jpg" ));
>
> > I've also tried
> > getClass().getResource() and the jar file won't even open
>
> What do you mean the "jar [sic] file won't open"? Are you trying to
open the
> JAR file? You should be opening the image file.
>
> You say you're using the method, but you don't show us *how* you're
using it.
> The problem is in how you're using the method.
>
> To give help, we must have enough information.
> <http://sscce.org/>
>
> --
> Lew
What I mean when I say that the jar file won't open is that when I
double-click on it, it will not execute. I always make sure that the
program runs BEFORE I jar it all up. But I can't get things to run
properly - and sometimes not at all - from the jar.
For example, when I use the following line, the program runs fine when
the images folder is in the same folder as the jar file. But when I
move the jar file, it opens, but doesn't have the image. That tells
me that it is NOT reading from the image folder inside the jar.
myCardBack = new ImageIcon("images/background.jpg");
When I change it to
myCardBack = new ImageIcon(getClass().getResource("images/
background.jpg"));
The jar file won't even execute. Actually, I suspect that it may
execute, but is hanging up somewhere before anything becomes visible.
My suspicion is based on the fact that I can't delete the jar file. I
get an error indicating that it is "in use". Again, the program runs
fine when it is NOT jarred.
I've also tried
myCardBack = new
ImageIcon(Toolkit.getDefaultToolkit().getImage("images/
background.jpg"));
Same result - the jar file either will not execute or is hanging up
somewhere. Program works fine un-jarred.


|