Piet Souris wrote:In the link that I gave there is a description of how to draw and erase a rectangle, but you said it was not what you want. Another method is
draw your image to the panel in your paintComponent, then draw the rectangle as you described it. On the next paintComponent (after another mousedragged event), the original image is drawn again, without the rectangle and again you draw the new rectangle. When you get the mousereleased event, do whatever it is what you must do
Or, to put it more simply (I think), just have every call to paintComponent paint the entire component with the moving rectangle in the place where it's supposed to be now.
You may respond that you think it would be faster to just erase and redraw the rectangle. The industry standard term for that is "Premature Optimization". First get a working solution (e.g. Piet's). If you find it too slow, then it's fine to try something else (if you can make it work).