Solved

Scrolling on a JPanel

Posted on 2006-07-23
4
1,144 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:tykkebror
  • 2
  • 2
4 Comments
 
LVL 92

Accepted Solution

by:
objects earned 400 total points
Comment Utility
In JPanelScroll use a JApplet instead of an Applet
And don't override paint()
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
>                     ((JPanel)currentEvent.getSource()).scrollRectToVisible(scrollRect);

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


0
 

Author Comment

by:tykkebror
Comment Utility
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
0
 

Author Comment

by:tykkebror
Comment Utility
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 :)
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now