• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to know when JScrollPane is scrolled by user?  RSS feed

 
Bin Smith
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

I want to know when JScrollPane is scrolled by user.
I tried to add MouseMotionListener to JScrollPane but it nevers works when I press mouse on scroll bar and drag it.
This causes JScrollPane to scroll but how to grasp this event. mouseDragged is not called when I drag scroll bar.

Thank you!
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Obtain horizontal/vertical JScrollBar from the JScrollPane as required.
Add adjustmentListener to the JScrollBar
Get notified of "scrolling"
 
Bin Smith
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
This really works.

But my problem is a little different.
When user exits by mouse my jdialog then mouseExited works and hides jdialog.
Unfortunately when scrolling by dragging mouse user might exit jdialog.
This causes mouseExited method to execute and hide the dialog.
The problem is how to tell mouseExited method that user is only autoscrolling by dragging.
By your suggestion I know when scrolling starts but if user stopped scrolling outside jdialog it must be hidden.
Is there a way to know when user ended scrolling by dragging mouse?
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will have to rephrase and tell us what you are trying to do here. Hiding a dialog on mouse exiting is bad usability.
If you are interested in scroll events, where does the mouse drag come into the picture?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!