覆盖 Scala 面板坐标
我正在尝试覆盖 scala.swing.Panel 的坐标系。我只想在笛卡尔坐标系的第一象限中工作。因此,我希望将面板的左下角标记为 (0,0),因此当鼠标在面板上移动时,将仅记录为正 x 和 y 值。有谁知道这是否可能?
谢谢!!
I am attempting to override the coordinate system of a scala.swing.Panel. I want to work only in the first quadrant on the Cartesian coordinate system. Thus, I want the lower left hand corner of the panel to be noted as (0,0), and therefore the mouse will register as only positive x and y values when moving across the panel. Does anyone know if this is possible??
Thanks!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您只想平移坐标,使左下角是原点而不是右上角,请执行以下操作:
我认为您真的不想覆盖整个坐标系,因为它可能会对绘画和对齐组件造成严重破坏。
您可以做的另一件事是覆盖底层 JPanel 的
getMousePosition
方法:然后
,覆盖
getMousePosition
不会影响MouseClicked< 上报告的位置/code> 事件,因此与第一种方式相比并没有获得太多好处。
If you just want to translate the co-ordinates so that the bottom-left is the origin rather than the top-right, do this:
I don't think you really want to override the whole co-ordinate system, as it would likely play havoc with painting and alligning the component.
Another thing you could do would be to override the
getMousePosition
method of the underlying JPanel:Then
However, overriding
getMousePosition
doesn't affect the reported position on theMouseClicked
event, so doesn't gain much over the first way.