1

I have a rather strange problem or more a question with the paint()-method: I'm delevoping some application with a part that visualizes a stack of images. You can navigate through that stack with keyboard and mouse to see every image. One requirement is, that you should be able to actually see every image, even if you navigate fast though that stack. To proof that I added some log outputs in my paint() method to see what image is displayed, and all seemed to be ok. Then I captured one fast navigation with a (software) video grabber from the monitor, with an adequate framerate, to see in the recorded video, that a few images are skipped (the video contained always a couple of frames for every image that was shown on the monitor). I tested some other video grabbers with the same result. It seems to me that even if the paint()-method was called for actually every image, the monitor output skipped some of them. How can I avoid that? I hope you can understand my problem, and for this application it is a real problem.

Thanks in advance for any hints, Andy

Coffeepot
  • 11
  • 2
  • 1
    Interesting requirement ... is it really about humans **seeing** all images? I am wondering what sense it makes to display all images, when one can scroll so fast that you need a video grabber to hit this "problem" ... – GhostCat May 31 '16 at 09:32
  • Well, it's a "law" thing, not our own requirement. It is a medical application for reporting medical images and you really have to make sure to render each image of a given stack. – Coffeepot May 31 '16 at 09:38
  • another point is that even videos don't see all the images, because (nearly all) videos use compression. compressed videos might skip frames eg. (see https://en.wikipedia.org/wiki/Lossy_compression#Video) – Martin Frank May 31 '16 at 09:42
  • can you provide the code how you draw and the code where you trigger paint? – Martin Frank May 31 '16 at 11:08
  • Code for calling the paint()-Method is : `Graphics g = getGraphics(); try { if (g != null) { paint(g); } } finally { if (g != null) { g.dispose(); } }` and inside the overwritten paint()-Method was some console output (printed the current image number). – Coffeepot May 31 '16 at 11:23
  • **But the point is, independend from some piece of source code, if a paint()-method from a component is called, can I be sure that all the things drawn inside this method are actually visible on the monitor, or could it theoretically be that all this goes just to a buffer that is never visible?** – Coffeepot May 31 '16 at 12:15

2 Answers2

1

after paint you have to call revalidate on the component.Then the change will take effect.

Ajay
  • 87
  • 7
0

looking into documentation on painting we can see on a note:

NOTE: If multiple calls to repaint() occur on a component before 
the initial repaint request is processed, the multiple requests may 
be collapsed into a single call to update(). The algorithm for
determining when multiple requests should be collapsed is 
implementation-dependent. If multiple requests are collapsed, the 
resulting update rectangle will be equal to the union of the rectangles 
contained in the collapsed requests. 

so even if you call repaint in the proper order and all is drawn, it can happen that several paint events are collapsed int one.

it seems that you have take measures and when i read that documentation right, you have to update() the component explicitly after the repaint() call.

Martin Frank
  • 3,445
  • 1
  • 27
  • 47
  • honestly: i havent tried since i don't have the app to test it neither the video grabber to document it - i just **read** the documention... – Martin Frank May 31 '16 at 09:59
  • Of course, a call of repaint() will collect several calls, but we call the paint()-method directly with the correct Graphics-object from the GUI. Otherwise a cinemode would be impossible for us. Not nice, I know. – Coffeepot May 31 '16 at 11:02