Using Scrollbars in JGoView


I have a n application built atop JGoView, wherein I have a background map (a GIF image) on top of which nodes are displayed. I have a requirement to scale the image size and thereby want the scrollbars to activate when this happens. However, although the image scale changes, the scrollbars(both Horizontal and Vertical remain unchanged). Could you suggest any ideas? Any help is appreciated.

Thanks in advance

Several possibilities:
(1) call JGoDocument.setDocumentSize to make sure the document’s size is at least as big as your background image
(2) override JGoView.getDocumentSize and getDocumentTopLeft to make sure those methods return values that include the bounding rectangle of your background image
(3) don’t use JGoView.setBackgroundImage but instead create a non-Selectable JGoImage displaying your background image and add it to a background JGoLayer in your JGoDocument

Thanks Walter, your first suggestion was right on the money! - However there is another issue that has come up - Scaling the map larger and smaller (Zooming in and out) is working flawlessly but - when I call the ZoomToFit method in the view - The background map is also being scaled - This behaviour is not desirable - Can I turn this off only for the Background image alone in the view?

“Zoom to fit” is just supposed to change the scale and position of the view in its document. Changing the scale will change the scale at which everything is drawn, including the background image. So there really isn’t any difference between zooming in or out and zoom to fit.

Thanks for the Input Walter. Suppose I change the scale at which the view is being drawn (zooming in/out/to Fit), The view updates with the top-left corner as root - I would like this to happen from the center and not the top-left corner…would this be possible???

Thanks in Advance.

Actually, already does something similar when doing a control-mouse-wheel event, except that it tries to keep the mouse’s point in the document constant, instead of just the view’s center point in the document.

So you could define these methods in your view:
/** Get the Point in document coordinates for the center of the view */
public Point getExtentCenter() {
Point pos = getViewPosition();
Dimension siz = getExtentSize();
return new Point(pos.x + siz.width/2, pos.y + siz.height/2);
/** Change the scale while trying to keep the center at a particular point in the document */
public void rescaleWithCenter(double newscale, Point docPt) {
Dimension siz = getExtentSize();
setViewPosition(docPt.x - siz.width/2, docPt.y - siz.height/2);
And then call:
rescaleWithCenter(newscale, getExtentCenter());