How can I get the relative and absolute cursor position?

不问归期 提交于 2020-01-06 02:48:27

问题


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

I need:

  1. The absolute position (only relative to the current Display)
  2. The position relative to the currently active Control

回答1:


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);


来源:https://stackoverflow.com/questions/18356516/how-can-i-get-the-relative-and-absolute-cursor-position

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!