如何禁用JScrollPane标题中的鼠标滚轮滚动? [英] How to disable scrolling from mouse wheel in a JScrollPane header?

查看:352
本文介绍了如何禁用JScrollPane标题中的鼠标滚轮滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用带有 JScrollPane(包括JComponent)的SWING框架,其中包含行标题和列标题(它们也是JComponents)。当鼠标位于JComponent或这两个标题之一时,鼠标滚轮会引发滚动。

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.

我想要做的是当鼠标禁用此滚动在列标题上面,但我找不到直接的方法,也不能在JScrollPane实例中找到,也不能在JComponent中找到。
有关信息,我查看了这些来源:

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.

推荐答案

我认为你需要一个两步解决方案。

I think you need a 2 step solution.


  • 要禁用/启用整个组件的滚轮,请使用 setWheelScrollingEnabled() JScrollPane 上。

要有选择地执行此操作,请在JScrollPane上执行 addMouseListener()以捕获所有鼠标移动(包括输入和输入) aving)所以你会知道指针何时在标题中。每当此更改时,您可以打开或关闭滚动。

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.

这篇关于如何禁用JScrollPane标题中的鼠标滚轮滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆