Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

drawing on a JPanel without erasing the underlying drawings

 
Amit Agarwal
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I am using a JPanel (with double buffering on) to draw lots of shapes like lines, circles etc. When the user draws another shape, it is drawn over the existing shapes and a repaint for all shapes has to be called. Is it possible that the temporary/intermediate shapes being drawn on the shape do not overwrite / erase the underlying graphics. I want that the underlying graphics should be always visible. Also, it is possible that I have to draw more than one shapes in the temporary phase.
Thanks in advance.
Amit
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Amit,
Make sure you are overridding the Update method to avoid the erasing stage of painting.

Regards,
Manfred.
 
Amit Agarwal
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Manfred,
COuld you please elaborate on the exact use of the update() method. Also, i cannot avoid the erasing stage completely. I need to erase the temporary shapes that I make and at the same time keep the original shapes in the background. e.g. drawing a line with a mouse drag would require to draw an new line and erase the old line with the dragging.
Also, is it possible to place an invisible / transparent panel over the background panel that can be repainted without the need of repainting the background panel and also keeping the graphics on the background intact?
Amit
 
Shay Gaghe
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there
i dont know any way to erase the last drawed shape without demeged to underline shape. by ovrriding the update() like you did you can avoid the screen the clear itself. a partial solution is to move the clearing rect to your last drowed shape like this :

in this way only the last shape will be erased but what was under it will be erase as well. if you diside to go forther think about multiple panels and usinf of setVisible(true/false)
it may provide kind of solution.
best regards
Shay Gaghe
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic