I see no error in the keepInView method. At least not in the logic. Unless you aren't constantly calling keepInView. If you aren't constantly calling in(in the paintComponent() method) then it will stop, and keep on going.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com