File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Mouse events on JScrollBar arrows? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Mouse events on JScrollBar arrows?" Watch "Mouse events on JScrollBar arrows?" New topic

Mouse events on JScrollBar arrows?

Darrin Cartwright
Ranch Hand

Joined: Dec 27, 2002
Posts: 107
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!


[ December 21, 2005: Message edited by: Darrin Cartwright ]

Life is good on the Ponderosa,<br />but mind where you step.
Torgil Zethson

Joined: Nov 30, 2005
Posts: 9
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.
I agree. Here's the link:
subject: Mouse events on JScrollBar arrows?
It's not a secret anymore!