Link to home
Start Free TrialLog in
Avatar of tykkebror
tykkebror

asked on

Scrolling on a JPanel

Hi
i have the following applet : www.tykkebror.dk/scroll
source:
www.tykkebror.dk/scroll/ImagePanel.java
www.tykkebror.dk/scroll/JPanelScroll.java

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 :)
tykkebror
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>                     ((JPanel)currentEvent.getSource()).scrollRectToVisible(scrollRect);

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


Avatar of tykkebror
tykkebror

ASKER

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:
www.tykkebror.dk/scroll/edit/ImagePanel.java
www.tykkebror.dk/scroll/edit/JPanelScroll.java

Thank you
arrrrrgh why cant i edit my comments. Why cant I redo stuff.
My new applet url should be www.tykkebror.dk/scroll/edit

ohh and objects just posted twice ... same person :)