Cannot add images, icons to Java programs using Oracle JDeveloper

I just started using JDeveloper for making Java Swing GUI desktop applications and I cannot figure out or find in JDeveloper help that when I want to use images inside jLabels or gif icons for my jFrames, where do I put those image files so that when I build and run the program and lines like the following are executed, the images actually show up:

example:

aboutFrame.setIconImage(new ImageIcon("icons/info.gif").getImage());


So, where do I put my /icons folder with the   info.gif   image file in it?

Is there anything else I need to do, from inside JDeveloper, so that the above line setting an icon image from a gif file works?

I thought with this example just putting the image files into the /icons folder into the /classes folder associated with the JDeveloper project (<project_name>/classes/icons) would do it like with other Java IDE I have used such as JCreator, but it does NOT pull it in with JDeveloper when I run my application.

Why is that? What can I do so that images are shown in my running program?

The program compiles and runs, just no image icons are shown.

Thank you.
abarnaiAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DileepanCommented:
You may place the images relative to classes folder (classes/icons/info.gif) and load them like below

java.net.URL imgURL = getClass().getResource("icons/info.gif); // load from folder OR jar file

aboutFrame.setIconImage(new ImageIcon(imgURL).getImage());
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
abarnaiAuthor Commented:
Yes it worked! Thank you.

The original line was in a STATIC method though,  so I got the compiler message that getClass().getResource()  cannot be placed in a static method.

I moved it to the constructor of the class, and then it worked fine.
0
abarnaiAuthor Commented:
You made a small typo, not a big deal.
(Left off one quote mark in the code)
0
DileepanCommented:
Yes. there is a typo. Good to see that it helped
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.