Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-swt-dev] shell events

I am using Display.getActiveShell(), but it does NOT return the correct result.

I wrote an example application (attached) creating two shells. To each shell I add a shell listener. The methods shellActivated and shellDeactivated write to System.out which method was invoked and the title of the now active shell (received by calling Display.getActiveShell). The result looks like that:

shell 1 activated
shell 1 is active

shell 1 deactivated
shell 1 is active      <-- here is the error; which shell is really active?

shell 2 activated
shell 2 is active

Tested with SWT 3.1 M7 on a Windows XP SP2 machine.

Thanks,
Tom

Yu.You@xxxxxxxxx schrieb:
use Display.getActiveShell();

Yu

-----Original Message-----
From: platform-swt-dev-bounces@xxxxxxxxxxx [mailto:platform-swt-dev-bounces@xxxxxxxxxxx]On Behalf Of ext Thomas Braun
Sent: Saturday, May 07, 2005 11:36 AM
To: Eclipse Platform SWT component developers list.
Subject: [platform-swt-dev] shell events


Hello,

I have noticed that if a get ShellDeactivated event from a ShellListener and I ask the display for the active shell while the event is processed, I get the shell which has been deactivated and not the shell which is now the active one. Is that a correct behaviour? What have I to do, if I want to know which shell is now active?

Thanks,
Tom
_______________________________________________
platform-swt-dev mailing list
platform-swt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/platform-swt-dev

import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;


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

		final Shell shell1 = new Shell(display);
		shell1.setText("shell 1");
		shell1.setBounds(0, 50, 200, 100);
		shell1.addShellListener(new ShellAdapter() {
			@Override
			public void shellActivated(ShellEvent e)
			{
				System.out.println("\n" + shell1.getText() + " activated");
				System.out.println(display.getActiveShell().
					getText() + " is active");
			}
			@Override
			public void shellDeactivated(ShellEvent e)
			{
				System.out.println("\n" + shell1.getText() + " deactivated");
				System.out.println(display.getActiveShell().
					getText() + " is active");
			}
		});

		final Shell shell2 = new Shell(display);
		shell2.setText("shell 2");
		shell2.setBounds(250, 50, 200, 100);
		shell2.addShellListener(new ShellAdapter() {
			@Override
			public void shellActivated(ShellEvent e)
			{
				System.out.println("\n" + shell2.getText() + " activated");
				System.out.println(display.getActiveShell().
					getText() + " is active");
			}
			@Override
			public void shellDeactivated(ShellEvent e)
			{
				System.out.println("\n" + shell2.getText() + " deactivated");
				System.out.println(display.getActiveShell().
					getText() + " is active");
			}
		});

		shell1.open();
		shell2.open();
		while (!shell1.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	}
}

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature


Back to the top