发现屏幕上的位置,复合 [英] Find composite location on screen
问题描述
我屏幕键盘在Java中的SWT和AWT上实施。
一个重要的事情是将键盘移动到一个位置,所选文本字段可以显示和不撒谎背后的屏幕键盘上。
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.
有关AWT我可以检测当前所选组件的位置
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();
我如何能实现在SWT相同的逻辑?
我加入了的FocusListener的SWT事件队列获得当前选定的部件。但是,当我打电话
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);
我会得到的位置relativ父复合材料。
I will get the position relativ to the parent composite.
我怎样才能得到一个特殊的小部件relativ的位置,完整的画面?
How can i get the location of a special widget relativ to the complete screen?
推荐答案
我相信法<一个href=\"http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/graphics/class-use/Point.html\">Control.toDisplay()应该能够将您的坐标转换成那些相对于屏幕。
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:
package org.eclipse.jface.snippets;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class Bla {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
final Text t = new Text(shell,SWT.BORDER);
t.setBounds(new Rectangle(10,10,200,30));
System.err.println(t.toDisplay(1, 1));
Button b = new Button(shell,SWT.PUSH);
b.setText("Show size");
b.setBounds(new Rectangle(220,10,100,20));
b.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
System.err.println(t.toDisplay(1, 1));
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
这篇关于发现屏幕上的位置,复合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!