The background color for the component is white. Yes, I need to have the transparent background. I can somehow get around the issue by creating another non transparent image with white color :
// create a transparent background
BufferedImage drawCanvas = gc.createCompatibleImage(screenW,screenH,
Transparency.TRANSLUCENT);
BufferedImage whiteImage = gc.createCompatibleImage(screenW,screenH, Transparency.OPAQUE);
whiteImage_g2=whiteImage.createGraphics();
// set the image color white
fillWhite(whiteImage_g2,0,0,screenW,screenH);
.
.
//loop
// draw an Image on the background
g.drawImage(image, x,y,w,h);
// save previous position of the image
x0=x;
y0=y;
//clip off the white color image
clipImage=whiteImage.getSubimage(x0,y0,w,h);
// clear the background
g.drawImage(clipIamge,x0,y0,w,h);
//clip off the transparent background with whatever being drawn onto it
clipImage=drawCanvas.getSubimage(x0,y0,w,h);
//redraw the part of the background where image was
g.drawImage(clipImage, x0,y0,w,h);
//end loop
This works fine except that I have to create a non transparent buffered image with white color and waste some memory. I thought that I could just clip off the transparent background and fill it with white color. But it does not seem to work with transparent image. When I tried with the transparent image, the foreground image appears with a gray color clipped region when the foreground image is being dragged across the screen.
Thanks
Jay