如果子级未使用事件,则允许父级处理鼠标事件
我有这个框架:
这是发生的事情:
- 当我超过粉红色面板,滚动窗格工作得很好。
- 当我将鼠标放在深灰色 JTextArea 上时,滚动窗格不会收到该事件。
一般来说,我的问题是,如果组件没有处理该特定事件,即使该组件具有侦听器并且已启用,如何确保该组件的父级接收该事件?
也许一个具体的例子就可以了。
您可以看到计算器,计算器绘制在可缩放的图像面板上,并且可以通过 Ctrl + Wheel 事件进行放大和缩小,但是当我不按 Ctrl 时,我希望滚动窗格接收事件并滚动视口。 (我认为这就是总结)
亚当。
I have this frame:
Here is what happens:
- When I'm over the Pinkish panel, the scroll pane works just fine.
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
虽然不完全“整洁”,但我的 在这个问题中的答案 可能适合做你想做的事情。
您可以使用
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 aAWTEvent.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).
正如我在评论中所描述的,它工作得很好......
As I described in my comment, and it works fine...