0

I'm developing a java application for draw through the drag of the mouse. I need the JPanel to be transparent, but in this way lose the function rubber. With the getBackground() can set the transparent color to use, but the path is not going to erase what was previously drawn.

Igor Konoplyanko
  • 9,176
  • 6
  • 57
  • 100
user1169390
  • 151
  • 11

1 Answers1

1

Drawing with transparent means... drawing with transparent, so the previous color stays intact. What you want is clearing a part of the image (you're drawing on an image surface, right?). That can be done using the clearing rule of AlphaComposite.

// Assuming Graphics2D g, maybe from BufferedImage
g.setComposite(AlphaComposite.Clear);
// drawing now clears
kiheru
  • 6,588
  • 25
  • 31