如果子级未使用事件,则允许父级处理鼠标事件

发布于 2024-09-26 18:37:18 字数 437 浏览 0 评论 0原文

我有这个框架:

alt text

这是发生的事情:

  1. 当我超过粉红色面板,滚动窗格工作得很好。
  2. 当我将鼠标放在深灰色 JTextArea 上时,滚动窗格不会收到该事件。

一般来说,我的问题是,如果组件没有处理该特定事件,即使该组件具有侦听器并且已启用,如何确保该组件的父级接收该事件?

也许一个具体的例子就可以了。

您可以看到计算器,计算器绘制在可缩放的图像面板上,并且可以通过 Ctrl + Wheel 事件进行放大和缩小,但是当我不按 Ctrl 时,我希望滚动窗格接收事件并滚动视口。 (我认为这就是总结)

亚当。

I have this frame:

alt text

Here is what happens:

  1. When I'm over the Pinkish panel, the scroll pane works just fine.
  2. When I put the mouse over the Darker gray JTextArea the scroll pane does not get the event.

In general my question is how can I make sure the parent of a component receives the event if the component didn't handle that specific event, even if the component has a listener and is enabled?

Perhaps a specific example will do.

You can see the calculator, the calculator is drawn on a scalable image panel, and can zoom in and out by the Ctrl + Wheel event, but when I don't press Ctrl, I would like the scroll pane to receive the event and scroll the view port. (I think this sums it)

Adam.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦里兽 2024-10-03 18:37:18

虽然不完全“整洁”,但我的 在这个问题中的答案 可能适合做你想做的事情。

您可以使用 AWTEvent.MOUSE_WHEEL_EVENT_MASK 代替 MOUSE_EVENT_MASK,并在控制键状态合适时将事件传递到滚动窗格。

(如果幸运的话,有人会发布一个“真正的”机制来将事件转发到父组件)。

While not entirely "neat", my answer in this question might be adapted to do what you want to do.

Instead of a MOUSE_EVENT_MASK you'd use a AWTEvent.MOUSE_WHEEL_EVENT_MASK, and pass the event to the scrollpane when the control key state is appropriate.

(With any luck someone will post a "real" mechanism to forward an event to the parent component).

无敌元气妹 2024-10-03 18:37:18

正如我在评论中所描述的,它工作得很好......

As I described in my comment, and it works fine...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文