This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why isn't my image showing up?

 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • 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).

Help!

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 ]
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • 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):
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic