Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ImageIcon vs Image

 
Paul Chamsay
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
 
Rob Spoor
Sheriff
Posts: 20822
68
Chrome Eclipse IDE Java 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).
 
Darryl Burke
Bartender
Posts: 5155
11
Java Netbeans IDE Opera
  • 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!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!