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 see. It is because you used typed event handlers.  Please use untyped event handler.  see the example I modified. It works.

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


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);
		final MyListener listener = new MyListener();
		shell1.addListener(SWT.Activate, listener);
		shell1.addListener(SWT.Deactivate, listener);

		final Shell shell2 = new Shell(display);
		shell2.setText("shell 2");
		shell2.setBounds(250, 50, 200, 100);
		shell2.addListener(SWT.Activate, listener);
		shell2.addListener(SWT.Deactivate, listener);

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

class MyListener implements Listener {
	public void handleEvent(Event e) 
	{
		if(e.type==SWT.Activate) 
			System.out.println("\n" + e.display.getActiveShell().
		getText() + " is active");
		if(e.type==SWT.Deactivate) 
			System.out.println("\n" + e.display.getActiveShell().
		getText() + " is deactived");
		
	}

}


-----Original Message-----
From: platform-swt-dev-bounces@xxxxxxxxxxx [mailto:platform-swt-dev-bounces@xxxxxxxxxxx]On Behalf Of ext Thomas Braun
Sent: Tuesday, May 17, 2005 4:42 PM
To: Eclipse Platform SWT component developers list.
Subject: 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
> 


Back to the top