如何获得相对和绝对光标位置? [英] How can I get the relative and absolute cursor position?

查看:60
本文介绍了如何获得相对和绝对光标位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过SWT获取光标的当前位置?

How can I get the current position of the Cursor with SWT?

我需要:

  1. 绝对位置(仅相对于当前 Display 的位置)
  2. 相对于当前处于活动状态的 Control
  3. 的位置相对
  1. The absolute position (only relative to the current Display)
  2. The position relative to the currently active Control

推荐答案

这将获得相对于当前显示器的光标位置:

This gets the Cursor position relative to the current Display:

import org.eclipse.swt.widgets.Display;
[...]
Point cursorLocation = Display.getCurrent().getCursorLocation();


要获得相对于集中控件而言的位置 ,您必须对其进行翻译:

To get the position relative to the focused Control you have to translate it:

import org.eclipse.swt.widgets.Display;
[...]
Point cursorLocation = Display.getCurrent().getCursorLocation();
Point relativeCursorLocation = Display.getCurrent().getFocusControl().toControl(cursorLocation);

这篇关于如何获得相对和绝对光标位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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