• 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 ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

ImageIcon vs Image

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • 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: 21997
107
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
Ah, thanks!
 
Blood pressure normal? What do I change to get "magnificent"? Maybe this tiny ad?
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic