Solved

Scrolling on a JPanel

Posted on 2006-07-23
4
1,154 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 92

Accepted Solution

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

Expert Comment

by:objects
ID: 17164375
>                     ((JPanel)currentEvent.getSource()).scrollRectToVisible(scrollRect);

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


0
 

Author Comment

by:tykkebror
ID: 17164749
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
ID: 17164779
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This video teaches viewers about errors in exception handling.

726 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