In my swing application, i am plotting a graph with more than 20000 points. The graph should be such that. user is allowed to select certain area by mouse clicked, mouse Dragged and mouse released event. once the mouse released event is fired, it should open another graph with the selected points.
Challenge: I am showing the selected area graph by a rectangle. Means.. when the user clicks on the graph and drags the mouse, then choosen area will be shown as a rectangle. As long as the user drags, then the rectangle will also be elongated or decreases the size.
Issue is when we elongate the rectagle it calls the repaint method, which calls the repaint of the graph also as well. As the graph points are more than 20000, so the drawing of the rectangle is not in sync with the mouse dragged. if the no of points are less then drawing of the rectangle will be in sync. Is there any way i can repaint only the rectagle. means... there should be a transparent layer on the graph, so that when ever the mouse drag takes place then it should not repaint the original graph. I have tried repaint(x,y, width, height) method for repainting the selected part. but no use..
I am in tight deadlines.. I would be glad if someone helps me on this.
Joined: Mar 26, 2004
If you are working with a JFrame, maybe you could make use of the GlassPane?
Joined: Jan 14, 2004
Here's a possiblity. When you have finished drawing your 20,000 graph points and are ready to begin drawing your selection/clipping rectangle convert your graph data to a BufferedImage. This will be easier to (re)paint as the rectangle is drawn on/over it.
In the example below I made up a fake glass pane (non–opaque component) and put it over the graphing panel using OverlayLayout. Then on the first mouse press we switch from data to buffered image in DotPanel (initiated in mousePressed). Actually you could skip the overlay panel and draw the rectangle directly on the buffered image if you like.