views:

124

answers:

2

Hi,

I have got a JScrollPane with a diagram inside. The paintComponent Methode of the diagram is overridden. Now when the diagram paints itself, the scrollpane scrolls down to the buttom.

How do I prevent the scrolling? I want the scrollpane / scrollbar to hold its position when painting.

Thanks in advance.

A: 

I've never seen this happen. Its probably because of some code you added to your paintComponent() method.

You could try using repaint(Rectangle) to limit the repainting that is done.

If you need more help post your SSCCE that demonstrates the problem.

camickr
Thanks for answering. I like to post SSCCE. Unfortunately in this case the diagram is based on multiple legacy superclasses. It has thousands lines of code. It is not possible to cut parts aeay easily. So if this is realy not a problem of the scrollpane / scrollbar itself, the scrollpolicy or something like that, I have to analyse it on my own.
A: 

There's no behavior in a typical Swing component that would cause it to scroll when paintComponent is called. I would look in your custom painting code for calls to a method called scrollRectToVisible. This is a common way of causing a component to be scrolled within it's pane.

Tom Martin