Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the relative and absolute cursor position?

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
like image 346
Kaadzia Avatar asked Nov 08 '25 10:11

Kaadzia


1 Answers

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);
like image 156
Kaadzia Avatar answered Nov 10 '25 01:11

Kaadzia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!