B
Brandon McCombs
hello,
Tonight I started to structure all my classes using packages and after
getting all the 'package' and 'import' statements working properly I ran
into issues with the code that loads images (nullpointer exceptions).
They were all working prior to the package changeover.
Previously I had this:
setIcon(new ImageIcon(LDAPMgr.class.
getResource("images/contIcon.gif")));
This works for images as long as they are within the JAR file:
setIcon(new ImageIcon(LDAPMgr.class.
getResource("/org/rekkanoryo/ldapmgr/utilities/resources/contIcon.gif")));
The problem is that I don't want to have to specify the whole path. Is
there a relative path I can use? If so, what other statements are needed
to allow relative paths?
Also, I need the ability for the loading of images to work from within
the packaged JAR file but also through the context of the filesystem and
it doesn't seem like the new code above will work for files that are
loaded from outside the JAR file in the file system so what can I do to
fix images that load that way?
From the filesystem I used to use this(the initial filename is from the
JAR file for the default photo but the method I use has to work with
images that aren't in the JAR that a user may load from anywhere on disk):
fileName = "images/noPhoto.gif";
image = tk.getImage(LDAPMgr.class.getResource(fileName));
thanks
Tonight I started to structure all my classes using packages and after
getting all the 'package' and 'import' statements working properly I ran
into issues with the code that loads images (nullpointer exceptions).
They were all working prior to the package changeover.
Previously I had this:
setIcon(new ImageIcon(LDAPMgr.class.
getResource("images/contIcon.gif")));
This works for images as long as they are within the JAR file:
setIcon(new ImageIcon(LDAPMgr.class.
getResource("/org/rekkanoryo/ldapmgr/utilities/resources/contIcon.gif")));
The problem is that I don't want to have to specify the whole path. Is
there a relative path I can use? If so, what other statements are needed
to allow relative paths?
Also, I need the ability for the loading of images to work from within
the packaged JAR file but also through the context of the filesystem and
it doesn't seem like the new code above will work for files that are
loaded from outside the JAR file in the file system so what can I do to
fix images that load that way?
From the filesystem I used to use this(the initial filename is from the
JAR file for the default photo but the method I use has to work with
images that aren't in the JAR that a user may load from anywhere on disk):
fileName = "images/noPhoto.gif";
image = tk.getImage(LDAPMgr.class.getResource(fileName));
thanks