Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add an icon as a classpath resource to an SWT window created with WindowBuilder?

I'm trying to add an external icon from an *.ico file to a window that I'm creating using the WindowBuilder design window. I can select the shell, which brings up an "image" properties field. alt text That brings up the image chooser dialog box: alt text

How do I make my icon show up in this menu as a classpath resource? The image works if an absolute path is given, but I don't want to use that option in my application.

Thanks!

like image 351
Zoot Avatar asked Dec 23 '10 19:12

Zoot


People also ask

How to add image to classpath?

To easily add an icon to my classpath, I found my desired icon, right clicked it, selected "copy", then went to one of the packages of my project in Eclipse, right clicked, and selected "paste".


2 Answers

To easily add an icon to my classpath, I found my desired icon, right clicked it, selected "copy", then went to one of the packages of my project in Eclipse, right clicked, and selected "paste". The next time I brought up the image chooser dialog box, my local package had the icon listed as an available classpath resource, and I chose it. image chooser

I was able to export the project to a runnable JAR, and the icon still worked.

like image 98
Zoot Avatar answered Nov 15 '22 15:11

Zoot


The solution I find to be working is to create a jar containing your images and add it to your class path. Then you will be able to choose them from the dialog in your second screen shot.

I remember this used to work with directories that are in your build path. Now it seems to be forced to be in a jar package.

like image 20
Bahadır Yağan Avatar answered Nov 15 '22 14:11

Bahadır Yağan