capturing an image of a component?

Hi, I hava a custom jComponent (an animated circle, which is a hyperlink button).

I want to move this component across the sceen or get it to a buffered image.

I have no problem in making the graphic move across the screen, my problem seems to be capturing the actuall component.

I have tried the following code:

int wid = jButton1.getWidth();

int hie = jButton1.getHeight();

bi =new BufferedImage(wid, hie, BufferedImage.TYPE_INT_ARGB);

big = bi.createGraphics();

Image imi =null;

imi = jButton1.createImage(wid, hie);

if (imi ==null){

int imi2 = wid;

}

big.drawImage(imi, 0,0,this);

offGraphics.drawImage(bi, 50,50,this);

When this code run's in the update() mehtod, it shows nothing.

If I replace the big.drawimage, with something like big.drawLine, it works fine.

does anybody have any clues?

Cheers!

[1276 byte] By [3Pca] at [2007-10-3 4:53:40]
# 1

ok, I sorted it out, here is the correct code:

Component c = jtaButton1;

int w = c.getWidth();

int h = c.getHeight();

bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);

big = bi.createGraphics();

c.paint(big);

big.dispose();

now the strange thing is that the original component is flashing and the copy isn't. Now I presume that this has something to do with sync, becuase the component itself is runnig as an animation with an update thread, and the panel it's in is animated with it's own thread. So I would presume that they are running out of sync.

Any suggestions on how to get them in sync would be great?

Currently I have worked around it by repainting the bufferedimage over the top of the original component.

Cheers

3Pca at 2007-7-14 22:58:32 > top of Java-index,Security,Cryptography...