aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes drawing on a JPanel without erasing the underlying drawings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "drawing on a JPanel without erasing the underlying drawings" Watch "drawing on a JPanel without erasing the underlying drawings" New topic
Author

drawing on a JPanel without erasing the underlying drawings

Amit Agarwal
Ranch Hand

Joined: May 09, 2001
Posts: 92
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

Joined: Jan 09, 2001
Posts: 1492
Hi Amit,
Make sure you are overridding the Update method to avoid the erasing stage of painting.

Regards,
Manfred.
Amit Agarwal
Ranch Hand

Joined: May 09, 2001
Posts: 92
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

Joined: Sep 03, 2001
Posts: 102
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: drawing on a JPanel without erasing the underlying drawings
 
Similar Threads
Finding the color of a pixel
Shapes return 0's as coordinates, width & height
Drawing text inside a Graphics2D shape
previously drawn shapes disappear when new one is created
Graphics2D drawOval(int,int,int,int) method