I've got a routine that paints an insanely large graph inside a scroll pane. It's too big to paint before adding to the scrollpane - the menory requirements would be several gigs.
Because of the size of the graph I'm rendering the chart within the paint method of the scrollpane's child. Which works out well, however I'm noticing that every time a scrollbar is moved my paint routine is called twice - once with a clipping rect equal to the uncovered area scrolled to, and a second time with the clipping rect equal to the viewport's dimensions.
For example if my viewport is 245x195 & I scroll down by 3 pixels my paint routine gets called with g.getClipBounds()
set as follows:
java.awt.Rectangle[x=0,y=195,width=245,height=3]
java.awt.Rectangle[x=0,y=3,width=245,height=195]
... because I render within the paint routine this is causing flicker (I do my calcs as fast as I can, but there is a wee bit of a delay I guess). Questions:
Does anyone know how to prevent the 2nd paint call? This is plain-jane JScrollPane stuff I'm doing here - I have a component, I add it to the scrollpane, I add the scrollpane to a parent component. You can see this behavior even in the first image scrolling demo @ the swing tutorial.
If the answer to #1 is 'nope': can anyone think of a good way to deal with this ? Should I paint to some sort of image buffer, track recent paint calls & copy the image where possible ? I cannot imagine this being much faster than re-rendering, but any insight appreciated :-)