
Signature
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
> > i create a bufferedimage object, paint onto it, then redisplay it
> > periodically. this works fine for a while; after moving the frame to
[quoted text clipped - 5 lines]
> like broken component painting code. Perhaps your BufferedImage is
> fine, but you just need to repaint it to the component.
yes, i'm sure it is bufferedimage. i draw the image into the graphics
object i obtain in the paint method of a jcomponent. the jcomponent
is embedded in a jpanel that is contained inside a jframe. the jpanel
contains only this component, and spans the area of the frame. in my
jcomponent paint method i draw the image first into the jcomponent's
graphics object, then i perform some custom drawing on that graphics
object based on some recent events (ie. mouse move). basically, this
works fine for a while. then if i change the order of the frame (move
it back, then front), the underlying image is not drawn, but the
mouse-move graphics is. my guess would be that somehow the
bufferedimage memory had to be relinquished to the system. although
annoying, that is still ok as long as i have some way to realize that
the image is lost and i should recreate it, but as far as i know
bufferedimage does not provide methods for this, volatileimage does?
i'm not interested in using volatileimage really, unless it would
solve my problem.
> > on the other hand i tried using volatileimage, with either
> > ImageCapabilities(true) and ImageCapabilities(false), but in this case
[quoted text clipped - 4 lines]
> If contentsLost is returning true, then you wouldn't expect to have the
> contents displayed. Did you get that backwards?
in my paint() method i check whether contentsLost() is true. if it
is, i redraw into the image, then draw the image into the jcomponent
graphics, but the image graphics is not displayed.
> Nevertheless, I suspect you've got a more fundamental problem than using
> a VolatileImage. Let's solve the simpler BufferedImage problem first,
> then work out VolatileImage if you need it.
sure, that sounds good to me.
Chris Smith - 24 Jan 2004 02:14 GMT
> > > i create a bufferedimage object, paint onto it, then redisplay it
> > > periodically. this works fine for a while; after moving the frame to
[quoted text clipped - 7 lines]
>
> yes, i'm sure it is bufferedimage.
Okay.
> my guess would be that somehow the
> bufferedimage memory had to be relinquished to the system.
No, that's not the case. If you were to run out of memory using
BufferedImage, then your application would fail with an
OutOfMemoryException. Under no circumstances would the system just
throw away the contents of that image without telling you.
> i draw the image into the graphics
> object i obtain in the paint method of a jcomponent. the jcomponent
[quoted text clipped - 6 lines]
> it back, then front), the underlying image is not drawn, but the
> mouse-move graphics is.
This sounds *so* much like a broken paint that I'd like to see the
contents of that paint method. Can you post it?
I also wonder if you're unintentionally creating a new BufferedImage
somewhere; that would cause you to lose the contents but it wouldn't
show up until the next repaint. That sounds like your symptoms, right?

Signature
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
andrzej semeniuk - 24 Jan 2004 13:34 GMT
chris, you were absolutely right, the problem was in my code,
bufferedimage works fine. thanks very much for your help.
> > > > i create a bufferedimage object, paint onto it, then redisplay it
> > > > periodically. this works fine for a while; after moving the frame to
[quoted text clipped - 35 lines]
> somewhere; that would cause you to lose the contents but it wouldn't
> show up until the next repaint. That sounds like your symptoms, right?
that's a natural assumption. in my case i was not updating a flag
that indicated to construct and redraw the buffered image when it
should. stupid mistake, but that's why it's also the worst to debug.