This week's book giveaway is in the Agile and Other Processes forum. We're giving away four copies of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java and have Dr. Raoul-Gabriel Urma & Richard Warburton on-line! See this thread for details.
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.
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.
In DotPanel I used g2.drawRenderedImage which takes a BufferedImage and an AffineTransform. This makes it easy to scale/zoom into the clipped area using AffineTransform methods. Also BufferedImage has a getSubimage method.
Seems to work okay.
[ May 27, 2004: Message edited by: Craig Wood ]
posted 15 years ago
Hi Craig Wood, KR Campbell
Thanks a lot for the kind timely help.. It is working fine.
Best wishes and Regards, Ravindra N
What are you saying? I thought you said that Santa gave you that. And this tiny ad: