Scrolling on a JPanel

i have the following applet :

The applet is just a JPanel with a scrollpane. I want the applet to scroll up and down the image when the mouse is near the edge. My only problem is that I cant get rid of the flickering. Everytime the image is scrolled it flickers or draws strange white lines across it. It doesnt matter if I use the "mouse near the edge thing" or I use the scrollbar it still destroys the graphic. My questions is:
1. Is there an easier more correct way to do the "mouse near the edge thing"?
2. How do I remove the flickering/white lines?

Comments on structure of code or other suggestion are most welcome.

Thx in advance :)
Who is Participating?
objectsConnect With a Mentor Commented:
In JPanelScroll use a JApplet instead of an Applet
And don't override paint()
>                     ((JPanel)currentEvent.getSource()).scrollRectToVisible(scrollRect);

This call should also be made from the event dispatch thread using EventQueue.invokeLater()

tykkebrorAuthor Commented:
Thx both of you

Changing the Applet to JApplet and removing the paint method from JPanelScroll sure removed some of the flickering.
Using the EventQueue.invokeLater() method to call ((JPanel)currentEvent.getSource()).scrollRectToVisible(scrollRect); removed the rest.

new applet: www.tykkebror.d/scroll/edit
new source:

Thank you
tykkebrorAuthor Commented:
arrrrrgh why cant i edit my comments. Why cant I redo stuff.
My new applet url should be

ohh and objects just posted twice ... same person :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.