I'm attempting to display a pair of images in a swing gui. However, no
matter what i try, the images just won't seem to display. What i'm
trying to do is to subclass JPanel and use it to display the
java.awt.Image resources. I am loading the images from jpeg files and
using a MediaTracker to ensure that they're loaded.
And then, when the panel's setImage() method is called, it is supposed
to display the new image. However, it's not. It's displaying nothing
whatsoever. I have tried a few tacks on this, up to and including
replacing the JPanel subclass with a variant inheriting from the JLabel
class, and using its setIcon(). Nothing.
For some reason, these images just won't seem to display.
Is there a way i can be assured that they will? How do i go about
checking if they're loaded? Or, if that turns out not to be the
problem, can someone maybe give me some input on the rest of it, to
check it out? I can post the code in a zip file and supply a link to
it. The images, well, i can supply those too, but since it pulls from
a random selection out of about 10 Mb of images, i'll understand if no
one wants to snag that :)
Thanks again.

Signature
Chris R.
=======
http://offlineblog.com/
Andrew Hobbs - 25 Feb 2004 01:26 GMT
> I'm attempting to display a pair of images in a swing gui. However, no
> matter what i try, the images just won't seem to display. What i'm
[quoted text clipped - 17 lines]
> a random selection out of about 10 Mb of images, i'll understand if no
> one wants to snag that :)
How about including a piece of code, preferably a small self contained
program that runs but displays the problem you are having.
I presume that you are using the paintComponent(Graphics g) method in your
JPanel derived class to paint the image and doing it via the g.drawImage()
method.
And as for icons have you read the sun tutorial at
http://java.sun.com/docs/books/tutorial/uiswing/misc/icon.html
Cheers
Andrew
--
********************************************************
Andrew Hobbs PhD
MetaSense Pty Ltd - www.metasense.com.au
Australia
61 8 9246 2026
metasens AntiSpam @iinet dot net dot au
*********************************************************
> Thanks again.
>
> --
> Chris R.
> =======
> http://offlineblog.com/
Chris R. - 25 Feb 2004 14:33 GMT
> I presume that you are using the paintComponent(Graphics g) method
> in your JPanel derived class to paint the image and doing it via
> the g.drawImage() method.
No, i was working with a JLabel inserted into the panel as the sole
component, and setting the JLabel's icon to an ImageIcon made from the
image itself.
> And as for icons have you read the sun tutorial at
>
> http://java.sun.com/docs/books/tutorial/uiswing/misc/icon.html
Not yet. Gonna do so today, though. Thanks.
(And, as noted in my other reply, i have fixed it - not sure how, but i
think my problem was in layout, not display. And i'm using
Icon.paintIcon() to paint the image now, which is working famously.)

Signature
Chris R.
=======
http://offlineblog.com/
Andrew Thompson - 25 Feb 2004 01:34 GMT
"Chris R." ...
> I'm attempting to display a pair of images in a swing gui.
That's ..2 right?
> ...I can post the code in a zip file and supply a link to
> it.
That's a good start, but.. a zip file?
Just how much code does it take
to (not) load two images?
>..The images, well, i can supply those too, but since it pulls from
> a random selection out of about 10 Mb of images,
What.. they are each 5 meg are they?
Again, your example only needs 2,
count them *2* images to display
the problem you describe. And not
big ones either, a couple of 32x32,
256 color images should be enough.
>...i'll understand if no
> one wants to snag that :)
You might get some benefit
from looking at this..
http://www.physci.org/codes/sscce.jsp
By the time you have trimmed your
example to <10K and two images,
you will probably spot the mistake
yourself. If not, you will at least have
a _concise_ definition of the problem,
one that people will be more likely to
examine..
--
Andrew Thompson
* http://www.PhySci.org/ Open-source software suite
* http://www.PhySci.org/codes/ Web & IT Help
* http://www.1point1C.org/ Science & Technology
Chris R. - 25 Feb 2004 14:31 GMT
Alright, much as i'd like to take offense to that, you're right, i'm
being excessive.
I'd like to thank both you and A. Hobbs for the responses, which in
hindsight were more informative than i really merited :)
As it happens, i've fixed the problem. Admittedly, i don't know where
it was in the first place, but my fix involved redoing the (rather
crufty) layout of the dialog in which the panels were set, so it was
probably something there.
Thanks again for the help. Cheers.
<something excoriating>

Signature
Chris R.
=======
http://offlineblog.com/
Andrew Hobbs - 26 Feb 2004 02:00 GMT
> Alright, much as i'd like to take offense to that, you're right, i'm
> being excessive.
[quoted text clipped - 6 lines]
> crufty) layout of the dialog in which the panels were set, so it was
> probably something there.
One tip that I have if you are using GUI components which don't seem to be
displayed at all or as expected. I suggest going through your code and hard
coding a call to setBackground() to a different color for each component.
It is often easy to spot what the problem is since it is immediately obvious
whether a component is being displayed, what size it is, and where it is
being placed.
Cheers
Andrew
--
********************************************************
Andrew Hobbs PhD
MetaSense Pty Ltd - www.metasense.com.au
Australia
61 8 9246 2026
metasens AntiSpam @iinet dot net dot au
*********************************************************
> Thanks again for the help. Cheers.
>
[quoted text clipped - 4 lines]
> =======
> http://offlineblog.com/
Brian Pipa - 25 Feb 2004 22:52 GMT
Just for grins, you could checkout my example Splash.java splash screen
code here:
http://filenabber.com/free-java-classes
it loads an image and shows it on a JLabel
brian
Free java apps: http://www.filenabber.com
Chris R. - 28 Feb 2004 16:47 GMT
> http://filenabber.com/free-java-classes
I'm doing just that right now. Thanks kindly, i'll have to see if it's
license-compatible with any of the work i do, but still.
Oh (page has loaded)... That's *quite* compatible :) Thanks for the
generosity. I don't need it on this pass, but i'll let you know if i
do.

Signature
Chris R.
=======
http://offlineblog.com/