My application class constructor instantiates a JPanel extended class
which does a complex drawing at the initial showing. In the last part
of the same constructor I call a screen capture method that uses java.awt
Robot and javax.imageio to get a JPEG file of the drawing panel. The
problem is that unless I put a Thread.sleep() for two or three second
delay before the capture call, captured JPEG is sheer blank. If I could
use a while loop for waiting the completion of the drawing and the
layout in the container, what could be the conditional expression to
be written in the while clause?
Thanks in advance for all the Java GUI gurus.
Michael Rauscher - 19 Dec 2004 08:29 GMT
> My application class constructor instantiates a JPanel extended class
> which does a complex drawing at the initial showing. In the last part
[quoted text clipped - 5 lines]
> layout in the container, what could be the conditional expression to
> be written in the while clause?
The problem seems to be, that you're accessing awt/Swing methods from
outside the event dispatch thread.
Therefore it might be that not all pending events has been processed
before you capture the screen. Try to use invokeLater
(SwingUtilities/EventQueue) to call your capture method.
Bye
Michael