Difficult. You probably can't make a great improvement.
Are you using AffineTransforms or anything similar? Those are a lot slower. I had a similar app once with lots of shapes, although I could only drag the most recent shape. I found that the drawing method for each shape took approx 1.6 microseconds, but it was longer on the first attempt. With an AffineTransform applied, it took about 53 microseconds on the first attempt, rather faster subsequently, but it was enough of a difference to cause an unpleasant delay and multiple edges whenever another window was dragged across my app. I tried several things, suggested by something in the Java tutorial probably here; look near the bottom for "performance" and the link they give there, like using Floats instead of Doubles for the 2D objects, and using opaque objects, but that didn't help. Eventually in a fit of desperation, I put a javax.swing.Timer in my main JFrame class and set it to repaint the panel with the display on. A bit of trial and error suggested that the rendering problem were reduced to imperceptible with the Timer set to 333 (3 "ticks" per second).
Sorry I can't be any more helpful, but that is what I did when I had a similar problem.
Originally posted by Mathias Nilsson: Every time the mouse is moved over the JPanel that acts like a container for the rectangles 4 JSpinners is changed with the x, y , width and height for all selected rectangles.
Do you think updating the spinners is what's making things slow?
If I have say 50-100 rectangles and drag them around the screen it is very slow. Is there someway of making drawing faster for 50-100 rectangles that is beeing dragged around the screen?
Or do you think that actually drawing the rectangles is what's slow?
One trick here is you can paint the 50-100 rectangles onto something like a BufferedImage at the beginning of the drag, then paint only the image while the mouse is moving.
I have commented out the Spinners and improvement are better but not enough. I thought of a buffered image to. I have 2 rulers for measure mm for x and y and grids for A4, A5 documents. I have put thoose in buffered image and they are only painted ones.
The problem as I see it to but all the rectangles in an buffered image is that when I use the drag tool and "mark" all rectangles it van be done. But when i release the drag rectangle all rectangles marked will be repainted and can be resized , reshaped and so on. So it think that an buffered image could make the paint slower in some circumstances.
Any other optimization to think about. I do not use double in Rectangle2D just plain Rectangle2D with rounded corners if that is what the user have choosen.