Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

JFrame.setImageIcon does not work

Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody,

I am trying to set an image for my java application so that it does not have that default image in my toolbar when I have the application open. I am trying to do it by using the following code (I am including the rest in case it has something to do with the order)

My folder structure looks something like this;
+ project
   + res (Marked as resource folder in IntelliJ)
       - icon.png
   + src

The code does not give me an error. It just does not show the icon image I set, but uses the default java logo. the icon is 64x64 in size, in case it matters. I know it is better to use a list if icons for different sizes but that will be something for the future, if this works

* I also tried it using this code, but it didn't work either
Posts: 3517
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code works for me. To see your image not only in the titlebar of the frame, but also in the frame itself, you could do (assuming canvas is a JPanel)

where image is the image you are using for the frame.setIconImage

You can then see what image you have.
There's a way to do it better - find it. -Edison. A better tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!