Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding mouseListener directly to JScrollPane

Status
Not open for further replies.

stormbind

Technical User
Mar 6, 2003
1,165
GB
Hello everyone,

I tried something like the following and it compiles but doesn't doSomething().
Code:
JScrollPane a;
...
a.addMouseListener(new MouseListener(){
  public void mouseReleased(MouseEvent m){
    doSomething();
  }
  ...
}
I would like to doSomething() while a user is scrolling through text and JScrollPane documentation doesn't explicitly state how this is done.

Thank you very much.

--Glen :)

Memoria mihi benigna erit qui eam perscribam
 
Alright, it works with some changes:
Code:
a.getVerticalScrollBar().addMouseMotionListener(...)
Now for the tricky part: My application is not calling doSomething() immediately - sometimes I need to wriggle the pointer to fire the event!

That is something for which I would really appreciate a tip.

--Glen :)

Memoria mihi benigna erit qui eam perscribam
 
Solved.

Isn't it cool how writing to yourself helps your thinking?! :/

--Glen :)

Memoria mihi benigna erit qui eam perscribam
 
And it's also cool to post your own solutions to help others ...

Cheers,
Dian
 
Oh... well the solution was not clever enough to share [cry]

I attached doSomething() to both mouseDragged and mouseMoved listeners. It worked smoother with just one or the other, which is all I really needed.

--Glen :)

Memoria mihi benigna erit qui eam perscribam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top