Graphics2D gg = (Graphics2D) image.getGraphics();
- gg.copyArea(0, 0, imgWidth, getHeight(),
- -horizontal * av.getCharWidth(), 0);
-
- if (horizontal > 0) // scrollbar pulled right, image to the left
- {
- transX = (er - sr - horizontal) * av.getCharWidth();
- sr = er - horizontal;
- }
- else if (horizontal < 0)
- {
- er = sr - horizontal;
+ if (imgWidth>Math.abs(horizontal*av.getCharWidth())) {
+ //scroll is less than imgWidth away so can re-use buffered graphics
+ gg.copyArea(0, 0, imgWidth, getHeight(),
+ -horizontal * av.getCharWidth(), 0);
+
+ if (horizontal > 0) // scrollbar pulled right, image to the left
+ {
+ transX = (er - sr - horizontal) * av.getCharWidth();
+ sr = er - horizontal;
+ }
+ else if (horizontal < 0)
+ {
+ er = sr - horizontal;
+ }
}
-
gg.translate(transX, 0);
drawComponent(gg, sr, er);