Optimizing paint() in JScrollPane's viewport

Hi

I'm developing a graphic app. I added a JPanel to a JScrollPane. I did some drawing in the JPanel. Everytime when I scroll, JScrollPane would call the paint() method in the JPanel. I would like to optimize the drawing. Only paint when the scrolling has stopped.

What I am currently doing is to install a custom BoundedRangeModel to JScrollPane's horizontal and vertical JScrollBar. I override the setValueIsAdjusting() method. Then this method is invoked, I would examine the boolean value. If both of these are false, then I would perform a repaint.

Is there a more elegant way of doing this?

Thanks

Regards

Chuk

[663 byte] By [chukleea] at [2007-10-2 5:25:23]
# 1

yes, there is a better way to do this.

Right now, you are probably doing some costly painting operations in the JPanel's paint() method. This is the wrong approach.

Just do the costly painting the first time you need to display the panel, and when the data changes. Don't drawn on the graphics object directly, instead draw onto a buffered image.

There will be many requests to paint the p[anel, so each time can re-use the work you've already done by painting the buffered image in your paint() method.

There are many posting on this forum related to this technique.

jvaudrya at 2007-7-16 1:27:13 > top of Java-index,Desktop,Core GUI APIs...
# 2
Thanks. Just the advise I needed.RegardsChuk
chukleea at 2007-7-16 1:27:13 > top of Java-index,Desktop,Core GUI APIs...