• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Adding Image object to a Container

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Suma MM
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot! once again!!
reply
    Bookmark Topic Watch Topic
  • New Topic