views:

247

answers:

1

Hello,

I am currently working on a SWING frame with a JScrollPane (including a JComponent), with a row header and a column header (which are also JComponents). When the mouse is over the JComponent or one of these 2 headers, mouse wheel provokes scrolling.

What I want to do is to disable this scrolling when the mouse is over the column header, but I can't find a direct way nor in JScrollPane instance, nor in JComponent. For information, I had a look at these sources :

Thank you in advance if you have a way to do that.

+2  A: 

I think you need a 2 step solution.

  • To disable/enable the scroll wheel for the whole component, use setWheelScrollingEnabled() on the JScrollPane.

  • To do this selectively, do addMouseListener() on the JScrollPane to catch all mouse movement (including entering and leaving) so you'll know when the pointer is in the header. Whenever this changes, you can turn scrolling on or off.

Carl Smotricz
Ok, I tested that: actually, the custom MouseListener shall be added to the JComponent used for header (and not to the JScrollPane), but basically, it works. Thank you very much.
Sobe
Excellent! Thank you for playing guinea pig for my wild and crazy idea. I'm happy to see it worked. :)
Carl Smotricz