How to disable scrolling from mouse wheel in a JScrollPane header?

北城以北 提交于 2019-12-06 14:43:48

问题


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 :

  • Sun's Howto on JScrollPane
  • JScrollPane javadoc
  • JComponent javadoc

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


回答1:


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.




回答2:


yourJTable.getTableHeader().setReorderingAllowed(false);

should work, try it out.



来源:https://stackoverflow.com/questions/1803375/how-to-disable-scrolling-from-mouse-wheel-in-a-jscrollpane-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!