File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Reading icon using ImageIO.Read Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Reading icon using ImageIO.Read" Watch "Reading icon using ImageIO.Read" New topic
Author

Reading icon using ImageIO.Read

Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 601
Hello,
Currently, I put my icon for my Frame in my "src" folder, where src is inside of the application folder.
I am using Netbeans.

When this runs inside netbeans, it is fine. But when it is compiled as a jar, I've got null exception thrown by this method as it is running.
I've put the same .png file inside the dist folder. Where am I supposed to put the JFrame folder's icon?
Thanks
Jack
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18882
    
    8

It should go in the root folder in the jar file. That's what it means to use an absolute URL, as you did in that case. Your Netbeans "src" and "dist" folders have nothing to do with anything once you generate the jar, so just forget about them. If they are in the jar, then you have done something wrong while creating it.

And by the way it's less confusing to just use an ordinary absolute URL, like this:
Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 601
Hi Paul,
I am still experiencing some difficulties, I use the directory as you informed me.
I put the bokss.png file in the same folder with the manifest.mf and build.xml.
I even can't execute the application in netbeans.
Thanks
Jack
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19759
    
  20

Actually Paul, the original resource was relative to the class file itself (the ./ works in resources just like in file systems). And that's where the icon should be - inside the JAR file. Don't assume it automatically gets packed. Check if it is, and if it isn't make sure it is.

The location inside the JAR file also matters. If the resource is relative (like ./bokss.png) then the icon must be located relative to the class file. If it's absolute (like /bokss.png) then it must be located to the root of the JAR file. Unlike the manifest file which must be placed inside the META-INF folder inside the JAR file.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18882
    
    8

Rob Spoor wrote:Actually Paul, the original resource was relative to the class file itself (the ./ works in resources just like in file systems).


That's why I used the word "confusing" in my response. When "./abc" is the same thing as "abc" then you should not use the more complicated form.
Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 601
Paul Clapham wrote:
Rob Spoor wrote:Actually Paul, the original resource was relative to the class file itself (the ./ works in resources just like in file systems).


That's why I used the word "confusing" in my response. When "./abc" is the same thing as "abc" then you should not use the more complicated form.


2 points I would like to raise
I can do one of the options either
1) add the bokss.png file to the jar file
2) modify the manifest.mf



I prefer the second method to the first. How do I modify this file to include the png file?
Thanks
Jack
Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 601
Jack Luk wrote:
Paul Clapham wrote:
Rob Spoor wrote:Actually Paul, the original resource was relative to the class file itself (the ./ works in resources just like in file systems).


That's why I used the word "confusing" in my response. When "./abc" is the same thing as "abc" then you should not use the more complicated form.


2 points I would like to raise
I can do one of the options either
1) add the bokss.png file to the jar file
2) modify the manifest.mf



I prefer the second method to the first. How do I modify this file to include the png file?
Thanks
Jack


I've solved it. Sorry, but I've lost the link that I originally wanted to share with you. Just google something like "manifest.mf resource png"
But I can't get to it.
Thanks
Jack
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading icon using ImageIO.Read