• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

ImageIcon vs Image

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone,

Just wondering what the difference is between ImageIcon and Image?

Is ImageIcon used only for JApplets?

Thanks
 
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't really compare the two. An ImageIcon is an implementation of Icon that happens to use an Image as its source (hence the name). So you use Image in places where you need an Image (like when drawing, a window's icon) and (Image)Icon where you need an Icon (JLabel, JButton).
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'll answer your second question first: no, ImageIcon's usage is most certainly not restricted to Applets. It can be used wherever an Icon is required and an Image is available for constructing the desired (Image)Icon.

Read the Icon API for a better understanding. A simple implementation of Icon is a set of drawing instructions (the paintIcon method) and knows its size (getWidth, getHeight). That's all.

From the API for ImageIcon:
An implementation of the Icon interface that paints Icons from Images.

And the answer to your first question is: they are different classes, with different methods and constructors, in different packages... don't even try to compare them.

 
Paul Chamsay
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah, thanks!
 
If you look closely at this tiny ad, you will see five bicycles and a naked woman:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic