[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] How to let Popup Shell show up at the given location

Hello,

I need create a pupup shell that when a widget is clicked that popup shell can open at the Mouse location. I tried to call setLocation, but it doesn't work. the popup shell always show up at the top right corner at my desktop.

Can someone please what I should change to let the popup shell show up in the correct location? Please see the snippet to reproduce the problem.

Thanks,
Hongying Zhang



import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

public class testpopupShell {
	public static void main (String [] args) {
		Display display = new Display ();
		final Shell shell = new Shell (display);

		Button ok = new Button (shell, SWT.PUSH);
		ok.setText ("Show Popup Shell");
		ok.addMouseListener( new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent evt) {
				int style = SWT.NONE | SWT.BORDER | SWT.ON_TOP ;
				final Shell popup = new Shell ( shell, style );
				popup.setLayout( new GridLayout() );
				Label label = new Label( popup, SWT.NONE );
				label.setText("Pop up shell" );

				Button b = new Button( popup, SWT.PUSH );
				b.setText("Push to Close Shell");
				b.addMouseListener( new MouseAdapter() {
					@Override
					public void mouseUp(MouseEvent evt) {
						popup.close();
					}
				});

				popup.setLocation( evt.x, evt.y );
				popup.setSize(120, 100);
				popup.open();
			}
		});

		shell.setLayout (new RowLayout ());
		shell.pack ();
		shell.open ();
		while (!shell.isDisposed ()) {
			if (!display.readAndDispatch ()) display.sleep ();
		}
		display.dispose ();
	}
}