This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes Adding Image object to a Container Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Adding Image object to a Container" Watch "Adding Image object to a Container" New topic
Author

Adding Image object to a Container

Suma MM
Ranch Hand

Joined: Apr 30, 2001
Posts: 31
Hi!
Is there a way I can add an 'image' object to a container in an application? (not an applet)......
For ex., when i say:
Container c = getContentPane();
c.add (img1); //img1 is an image object
Error is generated. Can somebody suggest an alternative?
As such, in my application, I need display images along with a button for each of the image....I am not able to figure out how to do this.
Thanks for any help
-S
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

This doesn't work because an Image is not a component. Only components can be added to containers. This is not a big problem, though... just extend a component like a Canvas or a Panel to take an Image, then in the paint() method of your new component, paint the image. Here's a really simple ( but functional ) example that extends Panel...



HTH,
-Nate


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Suma MM
Ranch Hand

Joined: Apr 30, 2001
Posts: 31
Thanks a lot! once again!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Adding Image object to a Container