Scrolling a custom Component (e.g. JPanel) with overridden paint(Graphic g)
Hi.
I’m creating an application for modelling advanced electrical systems in a house. Until now I have focused on the custom canvas using Java2D to draw my model. I can move the model components around, draw lines between them, and so on.
But now I want to implement a JScrollPane to be able to scroll a large model. I’m currently using a custom JPanel with a complete override of the paint(Graphic g) method.
Screen-shot of what I want to scroll:
http://pchome.grm.hia.no/~aalbre99/ScreenShot.png
Just adding my custom JPanel to a JScrollPane will obviously not work, since the paint(Graphic g) method for the JPanel would not be used any more, since the JScrollPane now has to analyze which components inside the container (JPanel) to paint.
So my question is therefore: How do you scroll a custom Component (e.g. JPanel) where the paint(Graphic g) method is totally overridden.
I believe the I have to paint on a JViewport instructing the JScrollPane my self, but how? Or is there another solution to the problem?
Thanks in advance for any suggestions.
Aleksander.

