JViewport not being set correctly when I use setViewPosition(), please help

I am using a zooming tool inside a scrollpane and basically i zoom to a part of the panel and center it. I calculated the viewport position so that the mouse point will be in the center of the screen. My problem is that when i do the following:

Point newViewPoint = getNewPoint();

viewPort.setViewPosition(newViewPoint); //sets the new point scrollPane.setViewportView(viewPort.getView()); //sets it in scrollpane

}

The above gets the new Point for the Viewport and sets it in the ScrollPane. The problem is sometimes the coordinates set is not the one i set!! I used a While loop shown below:

while (scrollPane.getViewport().getViewPosition().x != newVviewPoint.x && scrollPane.getViewport().getViewPosition().y != newViewPoint.y) {

viewPort.setViewPosition(newViewPoint);

scrollPane.setViewportView(viewPort.getView()); //sets it in scrollpane

}

which makes sure that the value has been set correctly BUT when i do System.out.println(scrollPane.getViewport().getViewPosition()); sometimes the result is still different! Somethimes the X coordinate is off and sometimes the Y is off.

I am really not sure why the scrollpane is setting the coordinates that way- i am pretty sure there is enough "room" for those coordinates when i assign them... Please help!

Thank you.

[1351 byte] By [shaselaia] at [2007-11-15]