在屏幕上查找复合位置
我正在 Java 中为 SWT 和 AWT 实现一个屏幕键盘。 一件重要的事情是将键盘移动到可以显示所选文本字段的位置,并且不要位于屏幕键盘后面。
对于 AWT,我可以检测当前所选组件的位置,
Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
if (owner == null) {
return;
}
Point ownerLocation = owner.getLocationOnScreen();
Dimension ownerSize = owner.getSize();
如何在 SWT 中实现相同的逻辑? 我通过向 SWT 事件队列添加焦点侦听器来获取当前选定的小部件。 但是当我打电话时,
Point location = new Point(mTextWidget.getLocation().x, mTextWidget.getLocation().y);
Dimension dimension = new Dimension(mTextWidget.getSize().x, mTextWidget.getSize().y);
我将获得相对于父组合的位置。
如何获取特定小部件相对于整个屏幕的位置?
I am implementing a on screen keyboard in Java for SWT and AWT.
One important thing is to move the keyboard to a position where the selected text field can show and is not lying behind the on screen keyboard.
For AWT i can detect the position of the current selected component with
Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
if (owner == null) {
return;
}
Point ownerLocation = owner.getLocationOnScreen();
Dimension ownerSize = owner.getSize();
How can i implement the same logic in SWT?
I get the current selected widget by adding a focuslistener to the SWT event queue. But when i call
Point location = new Point(mTextWidget.getLocation().x, mTextWidget.getLocation().y);
Dimension dimension = new Dimension(mTextWidget.getSize().x, mTextWidget.getSize().y);
I will get the position relativ to the parent composite.
How can i get the location of a special widget relativ to the complete screen?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信方法 Control.toDisplay() 应该能够将您的坐标转换为相对于屏幕的坐标。
此 snippet 可能会说明您所追求的内容:
I believe the method Control.toDisplay() should be able to translate your coordinates into ones relative to the screen.
This snippet may illustrate what you are after: