Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mouse events on JScrollBar arrows?

 
Darrin Cartwright
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All!

Does anyone know how to get mouse events from the arrow buttons on the end of a JScrollBar? I have tried this...

.. but the event is only fired when the mouse is pressed over the "Thumb" or track area of the JScollBar. I can't use an AdjustmentListener because the contents are changing dynamically at run time and I need to be able to differentiate between a user generated event and a change to the contents.

Any help is appreciated!

Thanks,

Darrin
[ December 21, 2005: Message edited by: Darrin Cartwright ]
 
Torgil Zethson
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One straightforward way of doing it would be to traverse the component tree rooted at the JScrollBar. The buttons will be instances of javax.swing.BasicArrowButton (I think, but use JButton to be safe), so whenever you come across a child component that is an instance of that class you add your MouseListener.

Another approach would be to override the ScrollBarUI -- the buttons have protected access in BasicScrollBarUI.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic