Find composite location on screen


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) {
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?


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


    	while (!shell.isDisposed()) {
    		if (!display.readAndDispatch())

By : VonC

Looks like a bug in IE7.

I just tested on IE8, works as expected in IE8 mode, but exhibits the same behaviour in compatibility mode.

Update: messing about, it seems it the overflow:hidden style causing that.

By : leppie

Straight from Axis2 Web site, this is a tutorial covering Axis2 and Jax-Ws. You get the above error probably because the axis2-jaxws-1.3.jar is missing. Check your classpath.

You can of course use CXF with Tomcat and my personal opinion is that you would be better off with it.

This video can help you solving your question :)
By: admin