> because the Image returned by getImage() is null.
> Has anybody some suggestions how to get an image object from a panel
> that hasn't been displayed?

Signature
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
> > because the Image returned by getImage() is null.
> > Has anybody some suggestions how to get an image object from a panel
[quoted text clipped - 4 lines]
>
> /Thomas
Hi,
I think you are talking of something like this:
public Image getImage(JPanel aPanel) {
BufferedImage image = new BufferedImage(500, 500,
BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = image.createGraphics();
aPanel.paint(g2d);
return image;
}
But this gives me only a black image. Any further suggestions or do I
make a misstake?
Norbert
Babu Kalakrishnan - 29 Nov 2004 07:39 GMT
>>>because the Image returned by getImage() is null.
>>>Has anybody some suggestions how to get an image object from a panel
[quoted text clipped - 19 lines]
> But this gives me only a black image. Any further suggestions or do I
> make a misstake?
Probably because the Panel hasn't been validated. Since the panel hasn't
been added to anything, you will have to set its bounds manually and
also call validate on it so that it will perform a layout of its child
components. (In case the panel has child components, you need to
experiment a bit to see if the validate call really works - There are a
lot of places where AWT code will avoid performing validations if the
component is not visible)
BK