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

Why isn't my image showing up?

Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've create a class that extends Image and has in it a private BufferedImage object that it draws on and defers to it for any method calls. For example:

What i draw on the buffered image is a bunch of images that I load and lay out on the buffered image in a specific design. I've checked the following and they all check out as correct:

1. the buffered image width,height
2. every image is painted within the bufferedimage's width/height (for x,y)
3. every image does exist

For some reason, however, when i try to pass the image to a JLabel, via new ImageIcon( new MyImageClass() ), and add that to a JFrame's content pane, it always comes as an empty JFrame. It does get sized properly, however.

In checking which "Image" methods are called, only two are ever called (from what i can tell):

public int getWidth(ImageObserver o)
public int getHeight(ImageObserver o)

Why is that? It seems to me that to draw an image, a component would need to grab it's pixel data somehow. Any idea why it never calls any other methods? (BTW, when it does call those methods, it prints out the correct 160, 179 values).


More Info
* the images are all "png" images with some transparency
* I create the BufferedImage as:
BufferedImage b = new BufferedImage( w, h, BufferedImage.TYP_INT_RGB );
[ October 01, 2006: Message edited by: Dan Bizman ]
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I tried what you describe new ImageIcon( new MyImageClass() ) I get an exception in the console:

This works okay:

Another approach is to use composition (vis–a–vis inheritance):
The airline is called "Virgin"? Don't you want a plane to go all the way? This tiny ad will go all the way:
a bit of art, as a gift, that will fit in a stocking
    Bookmark Topic Watch Topic
  • New Topic