🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.api
Article #1243

Re: how do I draw a JPG to a panel/container

#1243
From: Gillmer J. Derge [TeamB]
Date: Wed, 17 Apr 2002 04:12
32 lines
2456 bytes
"PeterH" <!Sorry-TooMuchSpam!nope@nope.com> wrote in message
news:3cbcdf8a_1@dnews...
> I've typed in the following code (easy on the code review, I'm playing
with
> things :>).  And I was able to get things to load up without the code for
> the scaledImage.  I was trying to scale the image to the current frame
size.
> I saw the Image.getScaledInstance() and thought that would do it, but now
I
> can't see anything on the screen (no picture I mean).  If I take a look a
> the width method, it says -1, so that would lead me to believe the image
> hasn't loaded or has an error.  What do you think?

Images are strange, because you get back an object immediately, but they
load in the background.  So just because you got back a result from
getScaledInstance doesn't mean it has finished loading yet.

Before you draw it, you should make sure it has loaded.  The best way to do
that is with a MediaTracker.  Something like this will work.

    MediaTracker tracker = new MediaTracker(this);
    tracker.addImage(scaledImage, 0);
    tracker.waitForAll();

Once you get this working, you should probably only get a new scaled
instance when the frame's size changes and keep it cached so you can
repaint with the same image object each time.  Otherwise every time your
component needs to repaint, you'll be waiting for the image to be processed
which will introduce some sluggishness in the response.

--
Gillmer J. Derge [TeamB]
Technical Details
Message-ID: <3cbcf62f_1@dnews>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!arclight.uoregon.edu!enews.sgi.com!news.xtra.co.nz!newsfeeds.ihug.co.nz!ihug.co.nz!dnews
References: <3cb9ef73$1_1@dnews> <MPG.172579c5bd0dc2ea98b534@newsgroups.borland.com> <3cbc80fd$1_2@dnews> <3cbc9afb_2@dnews> <3cbcdf8a_1@dnews>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1089d0,422c9cef40be2392
X-Google-Attributes: gid1089d0,public
X-Google-ArrivalTime: 2002-04-16 21:14:03 PST
From: "Gillmer J. Derge [TeamB]" <spam@gillmerderge.com>
Newsgroups: borland.public.jbuilder.java.api
References: <3cb9ef73$1_1@dnews> <MPG.172579c5bd0dc2ea98b534@newsgroups.borland.com> <3cbc80fd$1_2@dnews> <3cbc9afb_2@dnews> <3cbcdf8a_1@dnews>
Subject: Re: how do I draw a JPG to a panel/container
Date: Wed, 17 Apr 2002 00:12:32 -0400
Lines: 35
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
NNTP-Posting-Host: 24.29.81.241
Message-ID: <3cbcf62f_1@dnews>
X-Trace: dnews 1019016751 24.29.81.241 (16 Apr 2002 21:12:31 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!arclight.uoregon.edu!enews.sgi.com!news.xtra.co.nz!newsfeeds.ihug.co.nz!ihug.co.nz!dnews