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

How about trying the snippet that is on SWT snippet site.  Note they are 
using Display.getCursorLocation().

public class Snippet233 {
	public static void main (String [] args) {
		final Display display = new Display ();
		final Shell shell = new Shell (display);
		shell.setText ("Parent Shell");
		shell.addMouseListener (new MouseAdapter() {
			public void mouseDown (MouseEvent e) {
				Shell dialog = new Shell (shell, SWT.DIALOG_TRIM | 
SWT.APPLICATION_MODAL);
				Point pt = display.getCursorLocation ();
				dialog.setLocation (pt.x, pt.y);
				dialog.setText ("Dialog Shell");
				dialog.setSize (100, 100);
				dialog.open ();
			}});
		shell.setSize (400, 400);
		shell.open ();
		while (!shell.isDisposed ()) {
			if (!display.readAndDispatch ()) display.sleep ();
		}
		display.dispose ();
	}
}


"Hongying Zhang" <hongying.zhang@xxxxxxx> wrote in message 
news:fsc3m1$vuj$1@xxxxxxxxxxxxxxxxxxxx
> 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 ();
> }
> }