Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: AWT
Expertise: Beginner
Jun 30, 1998

Image loading

Question:
I'm having trouble reshaping a frame to the size of a loaded image. I start out by saying:
    int fx = image.getWidth(this);
    int fy = image.getHeight(this);
then I try to apply it to the frame
    this.resize(fx, fy);
But, to my misfortune, the frame totally collapses to nothing but the title bar. What am I doing wrong?

Answer:
More than likely, either the image was not loaded properly, or it has not finished loading. You can check this by printing out the width and height values. If they are 0, the image isn't loaded. Since your frame is collapsing after the resize, the image dimensions are almost certainly 0. To make sure an image has finished loading, you must use a java.awt.MediaTracker. There is a very good example in the javadocs for MediaTracker on how to do this, so I won't go into the details here.

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date