This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 171933 - GUI builder doesn't handle icon paths correctly
Summary: GUI builder doesn't handle icon paths correctly
Status: NEW
Alias: None
Product: guibuilder
Classification: Unclassified
Component: Code (show other bugs)
Version: 6.x
Hardware: Macintosh Mac OS X
: P3 blocker (vote)
Assignee: issues@guibuilder
Depends on:
Reported: 2009-09-10 14:29 UTC by vbeffa
Modified: 2009-09-11 16:04 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Note You need to log in before you can comment on or make changes to this bug.
Description vbeffa 2009-09-10 14:29:07 UTC
The GUI builder prepends a "/" to icon paths for JButtons (in the generated code new javax.swing.ImageIcon(getClass().getResource("/image.tiff")) ). Thus they 
don't get loaded at runtime. Setting an absolute path (using the Image Chooser, of the form "file://") gets converted to "/Users/..." at runtime which is also 
wrong. Selecting an Image Within Project, after you select the image (you have to type the name, it doesn't even show up in the file chooser), doesn't work. The 
image name typed in is just ignored.
Comment 1 Peter Pis 2009-09-10 15:00:17 UTC
Comment 2 Jan Stola 2009-09-10 16:18:52 UTC
If you have your icon in Source Packages of your project then you should select it in 'Image Within Project' section of 
the icon property editor. The generated code with resource-name starting with slash ("/") should be correct e.g. it 
should be absolute resource-name of your icon. For example, if your icon is called icon.png and is located in 
com.myproject.resources then the resource-name should be "/com/myproject/resources/icon.png".

Is the resource-name of your icon correct? Have you rebuilt (e.g. invoked Clean & Build) the whole project when you've 
added the icon?
Comment 3 Tomas Pavek 2009-09-10 16:56:03 UTC
I've noticed you mentioned the generated code example:
> new javax.swing.ImageIcon(getClass().getResource("/image.tiff"))
Looks like the image was in the default package (i.e. no package). That would cause problems when trying to access via 
a resource name. Please make sure the image is under some package.
Comment 4 vbeffa 2009-09-10 22:54:15 UTC
Yes, the image name is correct. Currently it's in my src directory. I select the icon property of the button, then on the dialog select "Image Within Project," 
then the file chooser ("...") button. A second dialog comes up. It has 5 entries: Classpath, three jars in my project's lib folder (all with the path "/User/..."), 
and Source Packages. I expand Source Packages, it's empty. I type the image name manually. When I type it the OK button becomes enabled. I click OK but 
on the first dialog nothing has changed.

I try the same thing with External Image. Bring up the file chooser. Select "All Files" from the pull-down because my images is a tiff. Select it from my src 
directory and click OK. Now the File or URL: field says "file:/Users/vbeffa/NetBeansProjects/Mailer/src/TB_New.tiff". It shows up in my GUI builder, and also 
in Preview Design.

However, after a clean and build, when I run the project the button doesn't have the image as its icon.
Comment 5 Jan Stola 2009-09-11 11:22:54 UTC
> because my images is a tiff

I didn't pay attention to the extension of your icon before, but now I see that it is the root of your 'Image Within 
Project' part of the problem. I am able to reproduce it now. It seems that icon chooser wasn't designed with .tiff 
extension in mind.

Unfortunately, I am still not able to reproduce the 'External Image' part. It works correctly on my machine, but I am 
using Windows and I don't have access to Mac today. So, it may be Mac-specific. I will try it on Mac next week. Could 
you, please, check the generated code in this case. It seems that there's something wrong with it, maybe the initial 
slash that you mentioned in the first comment. Does the name of the file (in the generated code) start with the initial 
slash? Does it work if your try to run the same code with the initial slash removed/added? Thank you in advance.
Comment 6 vbeffa 2009-09-11 16:04:54 UTC
No, the external image path is correct, so I'm not sure why it doesn't work. On my Mac it's


There are no error messages in the system console, or reported Java exceptions, so I'm not sure what is happening.