1

I have tried and tried, but no matter what, I cannot add a simple .png icon image to a button control in WindowBuilder. I thought this answer to the question might help, but it doesn't.

Obviously, I want to add a group of .png files to the "classpath", whatever that is, but I cannot see how to do so. I've tried copying them to the /src folder, the /libs folder, I've tried bundling them up in to a .zip file and renaming it .jar, I've tried adding them to the Build Path several different ways… Nothing works.

Every time, when I click the […] button next to "icon" in the Properties pane in WindowBuilder while I have a button control selected, I am given a choice of four ways to have an icon. Only the first (Classpath resource) seems to be a truly viable option if I want the images to appear in the final program, but I only see the same six .jar files and one .zip file in the Parameters list on the left. Why can I never see the .png files I created, nor the .jar file I made out of them?

(I briefly toyed with the idea of posting some screenshots here—and I can still do so, if it would help—but I felt it might be redundant given they would be so similar to the ones in that other post I mentioned.)

halfer
  • 19,824
  • 17
  • 99
  • 186
Sturm
  • 689
  • 2
  • 23
  • 52
  • Have you seen this question: http://stackoverflow.com/questions/5657469/how-do-i-go-about-adding-an-image-into-a-java-project-with-eclipse – Bobulous Feb 14 '14 at 22:21
  • Yes, I've seen that question, but I'm afraid it didn't help. As I stated, I've already multiple ways of putting my .png files into a folder under /src, including having Eclipse create a new source folder for me first, as your linked article suggests. In addition, that whole bit about `classLoader.getResourceAsStream()` doesn't work for me, including the fixed version in the comments below. – Sturm Feb 16 '14 at 03:55
  • Perhaps I should explain the reason for this. I have some custom images that I want to use for buttons, instead of the default UI button look with text on it. I even have "rollover" and "down" states for the buttons. Does this make more sense? How do I do this? – Sturm Feb 18 '14 at 14:59
  • Never mind. I've discovered the problem. When I saved my image files, I didn't notice that Photoshop didn't put an extension on their filenames for me, like I thought it would be smart enough to do. Without extensions, Eclipse has no idea what those files are. Give them extensions (.png, in this case) and—surprise!—it all works as advertised. Sorry for my stupid mistakes. – Sturm Feb 18 '14 at 17:16

1 Answers1

0

I've discovered the problem.

When I saved my image files from Photoshop, I didn't notice that Photoshop didn't put an extension on their filenames for me, like I thought it would be smart enough to do. Without extensions, Eclipse has no idea what those files are. Give them extensions (.png, in my case) and—surprise!—it all works as advertised

I hope this helps anyone else, even though I doubt anyone else would be as dumb as I.

Sturm
  • 689
  • 2
  • 23
  • 52