Take the 2-minute tour ×

I have a JScrollPane component:

    scroller = new JScrollPane();

The bigPanel is painted into a bufferedImage which is displayed at startup and everything looks ok. I can scroll up and down without any problem. However when I enlarge bigPanel it updates the bufferedImage but saves only the part which is visible in JScrollPane (with correct dimensions, just the content outside of screen is blank).

I've tried to update buffered image on scroll bar change which is terribly expensive and causes that the image is rendered with white stripes in between...


So, is there a way how to paint the component the way it is done at the beginning or it's better to write my own scroller?

I'll try to work on minimal working code, but it's a bit difficult to isolate this. The panels consists of filled rectangles.

share|improve this question
is your bigPanel sets an image in background? if yes , try to resize the image in paintComponent method only.. –  ABC Mar 14 '12 at 15:21
How (as in SCCE) do you paint the bigPanel to the buffered image? It looks like you are painting the scroll pane to the image and not actually the bigPanel. You also want to turn off double buffering on the bigPanel when painting to the image. –  Walter Laan Mar 14 '12 at 15:41
add comment

1 Answer

up vote 2 down vote accepted

One approach is to scale the old BufferedImage using drawImage() while getValueIsAdjusting() remains true. Revise the BufferedImage only after adjustment ceases. If the update is time-consuming, incremental updates may be worth the effort.

share|improve this answer
thanks for tip, it works perfectly! when I'm using drawImage() I don't need doubleBuffering, right? –  Tombart Mar 16 '12 at 16:08
JPanel is double buffered by default, so I'd say no. –  trashgod Mar 16 '12 at 18:23
add comment

Your Answer


